Skip to content

Instantly share code, notes, and snippets.

@tobyhede
Created November 7, 2012 05:42
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 tobyhede/4029753 to your computer and use it in GitHub Desktop.
Save tobyhede/4029753 to your computer and use it in GitHub Desktop.
postgres-fu

list tables

SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_name ASC

list column names

SELECT column_name FROM information_schema.columns WHERE table_name ='training_contracts' ORDER BY column_name ASC;

list indexed columns

select
    t.relname as table_name,
    i.relname as index_name,
    a.attname as column_name
from
    pg_class t,
    pg_class i,
    pg_index ix,
    pg_attribute a
where
    t.oid = ix.indrelid
    and i.oid = ix.indexrelid
    and a.attrelid = t.oid
    and a.attnum = ANY(ix.indkey)
    and t.relkind = 'r'
    -- and t.relname like 'aac%'
order by
    t.relname,
    i.relname;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment