MySQLs Describe emulator! - Mailing list pgsql-general

From Boulat Khakimov
Subject MySQLs Describe emulator!
Date
Msg-id 3AA44897.121D60F0@inet-interactif.com
Whole thread Raw
Responses Re: MySQLs Describe emulator!  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
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

pgsql-general by date:

Previous
From: The Hermit Hacker
Date:
Subject: Re: System V IPC semaphore configuration.
Next
From: Tom Lane
Date:
Subject: Re: MySQLs Describe emulator!