[ACCEPTED]-What's the easiest way to return a recordset from a PostgreSQL stored procedure?-plpgsql
Accepted answer
There is also the option of using RETURNS TABLE(...)
(as described 5 in the PostgreSQL Manual), which I personally prefer:
CREATE OR REPLACE FUNCTION get_countries()
RETURNS TABLE(
country_code text,
country_name text
)
AS $$
SELECT country_code, country_name FROM country_codes
$$ LANGUAGE sql;
This is effectively 4 the same as using SETOF tablename
, but declares the table 3 structure inline instead of referencing 2 an existing object, so joins and such will 1 still work.
You should be able to use output parameters, like 1 this:
CREATE OR REPLACE FUNCTION get_countries(country_code OUT text, country_name OUT text)
RETURNS setof record
AS $$ SELECT country_code, country_name FROM country_codes $$
LANGUAGE sql;
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.