postgresql - faire un desc
L'instruction 'DESCRIBE' n'existant pas sous Postgresql, voici un petit moyen simple de retrouver la structure d'une table.


SELECT pg_attribute.attname as fieldname,
    pg_type.typname as type,
    pg_attribute.attnotnull as notnull,
    pg_attrdef.adsrc as default
    FROM pg_attribute
    INNER JOIN pg_type
ON pg_attribute.atttypid = pg_type.oid
LEFT JOIN pg_attrdef
ON (pg_attribute.attrelid = pg_attrdef.adrelid
AND pg_attribute.attnum = pg_attrdef.adnum)
WHERE pg_attribute.attrelid = '<NomDeLaTable>'::regclass
AND pg_attribute.attisdropped='false'
AND pg_attribute.attname NOT IN
('tableoid','xmin','cmin','xmax','cmax','ctid','oid')
ORDER BY pg_attribute.attnum;

page précédente

delphes.org - 2018 - powered by beclair