Skip to content

Instantly share code, notes, and snippets.

@choplin
Created December 24, 2013 09:14
Show Gist options
  • Select an option

  • Save choplin/8110693 to your computer and use it in GitHub Desktop.

Select an option

Save choplin/8110693 to your computer and use it in GitHub Desktop.
CREATE FUNCTION eval(sql Text) RETURNS SETOF Record AS $$
BEGIN
RETURN QUERY EXECUTE sql;
RETURN;
END;
$$ LANGUAGE plpgsql;
SELECT * FROM eval('SELECT * FROM( VALUES (1), (3) ) AS t') AS (i Int);
i
---
1
3
(2 rows)
SELECT * FROM eval('SELECT * FROM( VALUES (1,''a''), (3,''b'') ) AS t') AS (i Int, c Text);
i | c
---+---
1 | a
3 | b
(2 rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment