pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Fork <mfork@toledolink.com>
To: Boulat Khakimov <boulat@inet-interactif.com>
Cc: pgsql-sql@postgresql.org
Cc: pgsql-general@postgresql.org
Subject: Re: [SQL] Re: MySQLs Describe emulator!
Date: Tue, 6 Mar 2001 10:38:43 -0500 (EST)
Message-ID: <Pine.BSI.4.21.0103061035440.17993-100000@glass.toledolink.com> (raw)
In-Reply-To: <3AA4F0DE.D96BA904@inet-interactif.com>

try starting psql with the -E option -- this displays all queries used
internally to the screen, i.e.:

bash-2.04$ psql -E
********* QUERY *********
SELECT usesuper FROM pg_user WHERE usename = 'mfork'
*************************

Welcome to psql, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help on internal slash commands
       \g or terminate with semicolon to execute query
       \q to quit

mfork=# \d test
********* QUERY *********
SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules
FROM pg_class WHERE relname='test'
*************************

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

        Table "test"
 Attribute | Type | Modifier 
-----------+------+----------
 t         | text | 
 d         | date | 


So to get the info displayed with \d, execute the query:

SELECT a.attname, t.typname, a.attlen, a.atttypmod, a.attnotnull,
a.atthasdef, a.attnum
FROM pg_class c, pg_attribute a, pg_type t
WHERE c.relname = '<<TABLE NAME>>' 
  AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid
ORDER BY a.attnum


Michael Fork - CCNA - MCP - A+
Network Support - Toledo Internet Access - Toledo Ohio

On Tue, 6 Mar 2001, Boulat Khakimov wrote:

> Hi,
> 
> 1) "\d table" can only be used in psql, you cant run a query like that
> using libpq for example
> 
> 2) as a programmer I need to be able to find out as much info as
> possible about any given field
>    which is what "describe" for in mySQL.
> 
> Regards,
> Boulat Khakimov
>       
> 
> -- 
> Nothing Like the Sun
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
> 




view thread (14+ messages)  latest in thread

Message-ID: <Pine.BSI.4.21.0103061035440.17993-100000@glass.toledolink.com>
Permalink:  ../Pine.BSI.4.21.0103061035440.17993-100000@glass.toledolink.com/
Also on:    postgresql.org/message-id/Pine.BSI.4.21.0103061035440.17993-100000@glass.toledolink.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: mfork@toledolink.com, boulat@inet-interactif.com, pgsql-general@postgresql.org
  Subject: Re: [SQL] Re: MySQLs Describe emulator!
  In-Reply-To: <Pine.BSI.4.21.0103061035440.17993-100000@glass.toledolink.com>
  References: <3AA4F0DE.D96BA904@inet-interactif.com> <Pine.BSI.4.21.0103061035440.17993-100000@glass.toledolink.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox