types - Query the schema details of a table in PostgreSQL? -
i need know column type in postgresql (i.e. varchar(20)
). know find using \d
in psql, need done select query.
possible in postgresql?
you can describe table using postgres following query:
select a.attname column, pg_catalog.format_type(a.atttypid, a.atttypmod) datatype pg_catalog.pg_attribute a.attnum > 0 , not a.attisdropped , a.attrelid = ( select c.oid pg_catalog.pg_class c left join pg_catalog.pg_namespace n on n.oid = c.relnamespace c.relname ~ '^(tablename)$' , pg_catalog.pg_table_is_visible(c.oid) )
tith retrieve column names , data type.
it possible start psql client using -e
option
$ psql -e
and simple \d mytable
output queries used postgres describe table. work every psql describe commands.
Comments
Post a Comment