Hi
I am writing a function with PL/pgSQL, which returns result of some complex query with several tables. In manual i found such example:
But this code uses simple query SELECT * FROM table1 with single table.
I don't undestand how to write RETURNS SETOF .... in case with a more complex query as this:
Thank you.
I am writing a function with PL/pgSQL, which returns result of some complex query with several tables. In manual i found such example:
Code:
CREATE OR REPLACE FUNCTION Test() RETURNS SETOF table1 AS $$ DECLARE ret_row RECORD; BEGIN FOR ret_row IN SELECT * FROM table1 LOOP RETURN NEXT ret_row; END LOOP; RETURN; END; $$ LANGUAGE 'plpgsql';
I don't undestand how to write RETURNS SETOF .... in case with a more complex query as this:
Code:
SELECT a.name AS address_name, g.name AS goods_name, g.unit AS goods_unit, g.price AS goods_price
FROM set s
INNER JOIN goods g ON s.id_goods = g.id
INNER JOIN address a ON s.id_address = a.id
Comment