MySQLs Describe emulator!

From: Boulat Khakimov <boulat(at)inet-interactif(dot)com>
To: pgsql-sql(at)postgresql(dot)org, pgsql-general(at)postgresql(dot)org
Subject: MySQLs Describe emulator!
Date: 2001-03-06 02:16:55
Message-ID: 3AA44897.121D60F0@inet-interactif.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

Hi,

Here is a nifty query I came up with
that provides a detailed information on any row of any table.
Something that is build into mySQL (DESC tablename fieldname)
but not into PG.

SELECT a.attname AS Field,
c.typname as Type,
a.atttypmod-4 AS Size

FROM pg_attribute a,
pg_class b,
pg_type c

WHERE a.attrelid=b.oid
AND a.attname='[fieldname]'
AND b.relname='[tablename]'
AND c.OID=a.atttypid;

Output looks like this
funio=# SELECT a.attname AS Field, c.typname as Type,
funio-# a.atttypmod-4 AS Size
funio-# FROM pg_attribute a, pg_class b, pg_type c
funio-# WHERE a.attrelid=b.oid
funio-# AND a.attname='company'
funio-# AND b.relname='tbluser'
funio-# AND c.OID=a.atttypid;

field | type | size
---------+---------+------
company | varchar | 50
(1 row)

Pretty nifty huh? ;)

If I have time im gonna make a buildin function (DESC) out of it

--
Nothing Like the Sun

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-03-06 02:46:17 Re: MySQLs Describe emulator!
Previous Message The Hermit Hacker 2001-03-06 01:26:22 Re: System V IPC semaphore configuration.

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2001-03-06 02:46:17 Re: MySQLs Describe emulator!
Previous Message Christopher Sawtell 2001-03-06 02:14:59 Re: count number of weeks??