Re: Re: [GENERAL] MySQLs Describe emulator! - Mailing list pgsql-sql

From Michael Fork
Subject Re: Re: [GENERAL] MySQLs Describe emulator!
Date
Msg-id Pine.BSI.4.21.0103061035440.17993-100000@glass.toledolink.com
Whole thread Raw
In response to Re: [GENERAL] MySQLs Describe emulator!  (Boulat Khakimov <boulat@inet-interactif.com>)
Responses Re: Re: [GENERAL] MySQLs Describe emulator!
List 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@postgresql.org
>


pgsql-sql by date:

Previous
From: Karel Zak
Date:
Subject: Re: [GENERAL] Re: MySQLs Describe emulator!
Next
From: clayton cottingham
Date:
Subject: Re: platform independend db access?