Skip site navigation (1) Skip section navigation (2)

Re: DESCRIBE for composite type?

From: "Richard Broersma" <richard(dot)broersma(at)gmail(dot)com>
To: "Nikita Koselev" <koselev(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: DESCRIBE for composite type?
Date: 2008-10-05 15:13:17
Message-ID: 396486430810050813j7db2debawc649143306ad5ee7@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
On Sat, Oct 4, 2008 at 11:54 PM, Nikita Koselev <koselev(at)gmail(dot)com> wrote:

> How can I get description of this composite type later (field names
> and values)? Is there something in pgsql like DESCRIBE statement in
> oracle?

In the psql client, you simple called the client function \d
<functionname>.  Notice also, the queries that psql sends to the
PostgreSQL server inorder to produce the desired results.

testdb=# \d requirement_vo
********* QUERY **********
SELECT c.oid,
  n.nspname,
  c.relname
FROM pg_catalog.pg_class c
     LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relname ~ '^(requirement_vo)$'
  AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 2, 3;
**************************

********* QUERY **********
SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules,
relhasoids , reltablespace
FROM pg_catalog.pg_class WHERE oid = '26098'
**************************

********* QUERY **********
SELECT a.attname,
  pg_catalog.format_type(a.atttypid, a.atttypmod),
  (SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)
   FROM pg_catalog.pg_attrdef d
   WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef),
  a.attnotnull, a.attnum
FROM pg_catalog.pg_attribute a
WHERE a.attrelid = '26098' AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
**************************

 Composite type "testschema.requirement_vo"
       Column        |         Type
---------------------+-----------------------
 name                | character varying(20)
 description         | character varying(20)
 requirement_id      | integer
 requirement_type_id | integer
 priority_id         | integer
 necessity_id        | integer
 lower_limit         | double precision
 upper_limit         | double precision

testdb=#


-- 
Regards,
Richard Broersma Jr.

Visit the Los Angeles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug

In response to

pgsql-novice by date

Next:From: Ertel, SteveDate: 2008-10-07 17:13:16
Subject: postgres launch os applications
Previous:From: Tom LaneDate: 2008-10-05 15:11:18
Subject: Re: array of composite types - how can I launch this function with an array of composite values

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group