Quantcast
Channel: Question and Answer » postgresql
Viewing all articles
Browse latest Browse all 1138

Return type of JOINing stored procedure – PostgreSQL

$
0
0

Is it possible to express return type of stored procedure that returns joined tables using table type of one of joined tables?

My stored procedure looks like this:

CREATE or REPLACE FUNCTION selectJoin()
RETURNS SETOF ???
AS $$
BEGIN
    RETURN QUERY SELECT t1.*, t2.name
                 FROM t1, t2
                 WHERE t1.t2_id = t2.id;
END; $$
LANGUAGE plpgsql;

Table t1 has many (approx 70) columns so I’d like to somehow reuse the t1 type in RETURNS clause. Something like (t1, varchar(30)) or composite type inheritace. Is is possible?

PostgreSQL version 9.3


Viewing all articles
Browse latest Browse all 1138

Trending Articles