I have the query for example "select id, field1, field2 from table1" (id and field1 are integer and field2 is varchar) and I need call the query from function and return result as is.
CREATE OR REPLACE FUNCTION get_all_record()
RETURNS TABLE(id integer , field2 varchar(20)) AS
$$
BEGIN
EXECUTE 'SELECT table1.id, table1.field2 FROM table1' INTO id, field2;
RETURN;
END;
$$
LANGUAGE plpgsql
but this solution returns only one record in one field. How can I correct it?
RETURN QUERY
instead ofEXECUTE '...' INTO
. – JNevill Feb 26 '16 at 17:28