Declarar la estructura de la tupla de un registro en PL / pgSQL

No puedo encontrar nada en la documentación de PostgreSQL que muestre cómo declarar un registro, o fila, mientras declaro la estructura de la tupla al mismo tiempo. Si no define la estructura de la tupla, aparece el error "La estructura de la tupla de un registro aún no asignado es indeterminada".

Esto es lo que estoy haciendo ahora, que funciona bien, pero debe haber una mejor manera de hacerlo.

CREATE OR REPLACE FUNCTION my_func()
  RETURNS TABLE (
    "a" integer,
    "b" varchar
  ) AS $
DECLARE r record;
BEGIN

CREATE TEMP TABLE tmp_t (
    "a" integer,
    "b" varchar
);
-- Define the tuple structure of r by SELECTing an empty row into it.
-- Is there a more straight-forward way of doing this?
SELECT * INTO r
FROM tmp_t;

-- Now I can assign values to the record.
r.a := at.something FROM "another_table" at
       WHERE at.some_id = 1;

-- A related question is - how do I return the single record 'r' from
-- this function?
-- This works:
RETURN QUERY
SELECT * FROM tmp_t;

-- But this doesn't:
RETURN r;
-- ERROR:  RETURN cannot have a parameter in function returning set

END; $ LANGUAGE plpgsql;

Respuestas a la pregunta(3)

Su respuesta a la pregunta