Skip to content

Instantly share code, notes, and snippets.

@hopsoft hopsoft/README.md
Last active Apr 19, 2019

Embed
What would you like to do?
Query the recommended column order for PostgreSQL tables
SELECT
pg_attribute.attname,
pg_type.typname,
pg_type.typalign,
pg_type.typlen
FROM
pg_class
JOIN pg_attribute ON pg_attribute.attrelid = pg_class.oid
JOIN pg_type ON pg_type.oid = pg_attribute.atttypid
WHERE
pg_class.relname = 'YOUR_TABLE_NAME'
AND pg_attribute.attnum >= 0
ORDER BY
pg_type.typlen DESC, pg_attribute.attname;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.