Skip to content

Instantly share code, notes, and snippets.

@benlemasurier
Created May 23, 2013 20:10
Show Gist options
  • Select an option

  • Save benlemasurier/5639040 to your computer and use it in GitHub Desktop.

Select an option

Save benlemasurier/5639040 to your computer and use it in GitHub Desktop.
SELECT
a.attname AS field,
t.typname AS type,
format_type(a.atttypid, a.atttypmod) AS complete_type,
a.attnotnull AS isnotnull,
(SELECT 't'
FROM pg_index
WHERE c.oid = pg_index.indrelid
AND a.attnum = ANY (pg_index.indkey)
AND pg_index.indisprimary = 't'
) AS pri,
(SELECT pg_attrdef.adsrc
FROM pg_attrdef
WHERE c.oid = pg_attrdef.adrelid
AND pg_attrdef.adnum=a.attnum
) AS default
FROM pg_attribute a, pg_class c, pg_type t
WHERE c.relname = 'admin_modifications'
AND a.attnum > 0
AND a.attrelid = c.oid
AND a.atttypid = t.oid
ORDER BY a.attnum;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment