Thread: DESCRIBE for composite type?

DESCRIBE for composite type?

From
"Nikita Koselev"
Date:
I've created an composite type.
--
CREATE TYPE requirement_vo AS (
 name VARCHAR(20),
 description VARCHAR(20),
 requirement_id INT,
 requirement_type_id INT,
 priority_id INT,
 necessity_id INT,
 lower_limit DOUBLE PRECISION,
 upper_limit DOUBLE PRECISION
 );
--
How can I get description of this composite type later (field names
and values)? Is there something in pgsql like DESCRIBE statement in
oracle?

Re: DESCRIBE for composite type?

From
"Richard Broersma"
Date:
On Sat, Oct 4, 2008 at 11:54 PM, Nikita Koselev <koselev@gmail.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