Skip to content

Instantly share code, notes, and snippets.

@neilalbrock
Created September 7, 2012 14:21
Show Gist options
  • Save neilalbrock/3666613 to your computer and use it in GitHub Desktop.
Save neilalbrock/3666613 to your computer and use it in GitHub Desktop.
PostgreSQL Dynamic SQL Function
CREATE OR REPLACE FUNCTION name(arg datatype)
RETURNS TABLE(column datatype) AS
$$
BEGIN
RETURN QUERY EXECUTE 'SELECT * FROM table WHERE column = $1' USING arg;
END;
$$
LANGUAGE plpgsql;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment