Thread: \d command
command
From
Mark Jewiss
Date:
Hello,

I want to be able to build up information about the different tables held
in a database for a small diagnostic tool that I'm writing.

I need to see the name of each column in the table, the column data type
and size, and if nulls are allowed - essentially what is produced by the
'\d <tablename>' command.

Does anyone know the SQL query to use on the system tables to produce that
result? I've started to go through them now, and was expecting to find
something along the lines of 'pg_columns', but no such luck. :(

Regards,

Mark.
--
Mark Jewiss
Knowledge Matters Limited
http://www.knowledge.com


command
From
Simon Drabble
Date:
On Mon, 27 Sep 1999, Mark Jewiss wrote:

> Hello,
>
> I want to be able to build up information about the different tables held
> in a database for a small diagnostic tool that I'm writing.
>
> I need to see the name of each column in the table, the column data type
> and size, and if nulls are allowed - essentially what is produced by the
> '\d <tablename>' command.
>
> Does anyone know the SQL query to use on the system tables to produce that
> result? I've started to go through them now, and was expecting to find
> something along the lines of 'pg_columns', but no such luck. :(
>
> Regards,
>
> Mark.
> --
> Mark Jewiss
>

Dunno the specific selects to get what you want, but you can investigate the
standard postgres views:

select * from pg_views where viewname like 'pg_%';

Might get you what you're after.

I was doing something similar (creating my own list of tables/ columns)
recently - the various selects are in the source, and quite well documented.


Simon.

--
 "Aah - a voice of clue in a wilderness of luse."

   Simon Drabble                      It's like karma for your brain.
   simon@eskimo.com


command
From
Bruce Momjian
Date:
See FAQ.  It is in psql.c.


> Hello,
>
> I want to be able to build up information about the different tables held
> in a database for a small diagnostic tool that I'm writing.
>
> I need to see the name of each column in the table, the column data type
> and size, and if nulls are allowed - essentially what is produced by the
> '\d <tablename>' command.
>
> Does anyone know the SQL query to use on the system tables to produce that
> result? I've started to go through them now, and was expecting to find
> something along the lines of 'pg_columns', but no such luck. :(
>
> Regards,
>
> Mark.
> --
> Mark Jewiss
> Knowledge Matters Limited
> http://www.knowledge.com
>
>
> ************
>
>


--
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

command
From
Rodney McDuff
Date:
HI Mark
> I want to be able to build up information about the different tables held
> in a database for a small diagnostic tool that I'm writing.
>
> I need to see the name of each column in the table, the column data type
> and size, and if nulls are allowed - essentially what is produced by the
> '\d <tablename>' command.
>
> Does anyone know the SQL query to use on the system tables to produce that
> result? I've started to go through them now, and was expecting to find
> something along the lines of 'pg_columns', but no such luck. :(

From man psql:

  -E   Echo the actual query generated by \d and other backslash commands

--

  +-----------------+------------------------------------------+
  |    _   ^   _    | Dr. Rodney McDuff                        |
  |   |\  /|\  /|   | Network Development, ITS                 |
  |     \  |  /     | The University of Queensland             |
  |      \ | /      | St. Lucia, Brisbane                      |
  |       \|/       | Queensland, Australia. 4072.             |
  |<-------+------->| TELEPHONE: +61 7 3365 8220               |
  |       /|\       | FACSIMILE: +61 7 3365 4477               |
  |      / | \      | EMAIL: mcduff@its.uq.edu.au              |
  |     /  |  \     |                                          |
  |   |/  \|/  \|   |        Ex ignorantia ad sapientiam       |
  |    -   v   -    |            Ex luce ad tenebras           |
  +-----------------+------------------------------------------+