Skip to content

Instantly share code, notes, and snippets.

@robertpostill
Created August 30, 2016 05:00
Show Gist options
  • Save robertpostill/4336d6d34a212155b46dd40ab249422f to your computer and use it in GitHub Desktop.
Save robertpostill/4336d6d34a212155b46dd40ab249422f to your computer and use it in GitHub Desktop.
COPY STATEMENT
COPY (SELECT string_agg(quote_ident(column_name) ||
CASE udt_name
WHEN 'timestamp' THEN '::timestamp(0)'
WHEN 'timestamptz' THEN '::timestamptz(0)'
WHEN 'text' THEN '::varchar(6000)'
ELSE ''
END,
','
)
FROM information_schema.columns
WHERE
table_schema = '$schema' AND
table_name = '$TBL')
TO STDOUT WITH DELIMITER AS '|' CSV HEADER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment