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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-novice by date

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