Re: [SQL] Re: MySQLs Describe emulator!

From: Michael Fork <mfork(at)toledolink(dot)com>
To: Boulat Khakimov <boulat(at)inet-interactif(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org, pgsql-general(at)postgresql(dot)org
Subject: Re: [SQL] Re: MySQLs Describe emulator!
Date: 2001-03-06 15:38:43
Message-ID: Pine.BSI.4.21.0103061035440.17993-100000@glass.toledolink.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

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(at)postgresql(dot)org
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Brett W. McCoy 2001-03-06 16:02:42 Re: INSERT ... RETURNING as Oracle
Previous Message Karel Zak 2001-03-06 15:37:32 Re: Re: MySQLs Describe emulator!

Browse pgsql-sql by date

  From Date Subject
Next Message clayton cottingham 2001-03-06 16:03:41 Re: [SQL] MySQLs Describe emulator!
Previous Message Karel Zak 2001-03-06 15:37:32 Re: Re: MySQLs Describe emulator!