pg view of table columns needed for scripting

Started by Gauthier, Daveover 15 years ago3 messagesgeneral
Jump to latest
#1Gauthier, Dave
dave.gauthier@intel.com

Hi:

Is there something like a pg_xxx view that I can use to get the column names and data types of a table, similar to what I see with \d ? I need to run this is a script, so \d isn't viable. I did a \df and looked around, but nothing popped out.

Thanks in Advance !

#2bricklen
bricklen@gmail.com
In reply to: Gauthier, Dave (#1)
Re: pg view of table columns needed for scripting

On Fri, Oct 22, 2010 at 9:14 AM, Gauthier, Dave <dave.gauthier@intel.com> wrote:

Is there something like a pg_xxx view that I can use to get the column names
and data types of a table, similar to what I see with \d ?  I need to run
this is a script, so \d isn't viable.  I did a \df and looked around, but
nothing popped out.

psql -E -d dbname

Will give you the internal queries that are executed by things like \d etc

#3Chris Barnes
compuguruchrisbarnes@hotmail.com
In reply to: Gauthier, Dave (#1)
Re: pg view of table columns needed for scripting

From: dave.gauthier@intel.com
To: pgsql-general@postgresql.org
Date: Fri, 22 Oct 2010 09:14:01 -0700
Subject: [GENERAL] pg view of table columns needed for scripting

Hi:

Is there something like a pg_xxx view that I can use to get
the column names and data types of a table, similar to what I see with \d ? I
need to run this is a script, so \d isn't viable. I did a \df and looked
around, but nothing popped out.

Thanks in Advance !

Specify the table name where like..

SELECT table_schema,table_name,column_name,data_type

FROM information_schema.columns

WHERE table_name like 't%'

and column_name = 'name_of_column_here' ORDER BY table_name

;
table_schema | table_name | column_name | data_type
---------------+-----------------------------------+---------------+-------------------
schema | table | column_name | character varying

Chris