Re: Selecting field names?

From: Charles Tassell <ctassell(at)isn(dot)net>
To: Michael Hall <michael(at)inteltec(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Selecting field names?
Date: 2000-04-10 03:25:11
Message-ID: 4.2.0.58.20000410002305.009c95d0@mailer.isn.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Yes, if you start psql with the -E switch (ie, psql -E -h dbserver
database) then do a \d tablename it will show you the SQL query that's used
to display the table definition. You can then use this to do your
selects. Here is what I get when I do the above:

QUERY: SELECT a.attnum, a.attname, t.typname, a.attlen, a.atttypmod,
a.attnotnull, a.atthasdef FROM pg_class c, pg_attribute a, pg_type t WHERE
c.relname = 'tablename' and a.attnum > 0 and a.attrelid =
c.oid and a.atttypid = t.oid ORDER BY attnum

QUERY: SELECT viewname, definition FROM pg_views WHERE viewname like
'tablename'

At 12:57 PM 4/9/00, Michael Hall wrote:
>Is there a way to 'select' the names of the fields and the field types
>of a table?
>
>--
>Michael J. Hall, CCA Intelligence Technologies Int'l
>michael(at)inteltec(dot)com http://www.inteltec.com
>secure: mikehall(at)leo(dot)gov

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Charles Tassell 2000-04-10 03:28:51 Re: PHP-Postgres link
Previous Message Titus Brown 2000-04-10 03:16:55 Minor hack to support LO string searches