Tuesday, June 14, 2011

PostgreSQL Metadata retrieval

# To get the oid of tables;
    SELECT oid FROM pg_class WHERE relname='m_menu';
# To get attribute details
    SELECT * FROM pg_attribute WHERE attrelid = 'm_menu'::regclass;
# To get only fields information
    SELECT * FROM pg_attribute WHERE attrelid = 'm_menu'::regclass and attnum>0;     
# To get table list     
    SELECT tablename FROM pg_tables where schemaname='public'  order by tablename;
# To get field information of a table
    SELECT a.attname, b.typname, attnum FROM pg_attribute a
    left outer join pg_type b on b.oid = a.atttypid
    WHERE attrelid = upper('claim_id')::regclass and attnum>0 order by attnum;

No comments:

Post a Comment