Skip to content

Instantly share code, notes, and snippets.

@hooopo
Last active May 9, 2019 20:49
Show Gist options
  • Save hooopo/31b91ad64b86a77ad7eda09fd7725e6e to your computer and use it in GitHub Desktop.
Save hooopo/31b91ad64b86a77ad7eda09fd7725e6e to your computer and use it in GitHub Desktop.
SELECT
pg_attribute.attname,
format_type(pg_attribute.atttypid, pg_attribute.atttypmod)
FROM
pg_index, pg_class, pg_attribute, pg_namespace
WHERE
nspname = 'public' AND
relname = 'orders' AND
indrelid = pg_class.oid AND
pg_class.relnamespace = pg_namespace.oid AND
pg_attribute.attrelid = pg_class.oid AND
pg_attribute.attnum = any(pg_index.indkey) AND
indisprimary;
attname | format_type
---------+-------------
id | bigint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment