Skip to content

Instantly share code, notes, and snippets.

@cetver
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cetver/4fd7b52fd9fe3820c4fe to your computer and use it in GitHub Desktop.
Save cetver/4fd7b52fd9fe3820c4fe to your computer and use it in GitHub Desktop.
Postgresql: list of columns in select
select string_agg('"table name|alias".' || '"' || column_name || '"' || ' AS "alias' || column_name || '"', E',\n')
from information_schema.columns
where
table_schema = 'public' AND
table_name = 'table_name'
group by table_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment