X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A768BD7BDC for ; Wed, 7 Sep 2005 18:39:02 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 57749-05 for ; Wed, 7 Sep 2005 21:38:34 +0000 (GMT) Received: from zhonka1.zhonka.net (zhonka1.zhonka.net [66.228.195.5]) by svr1.postgresql.org (Postfix) with ESMTP id 8EBFED7B55 for ; Wed, 7 Sep 2005 18:38:33 -0300 (ADT) Received: from wolf.pjkh.com ([66.228.196.74]) by zhonka1.zhonka.net (Post.Office MTA v3.5.3 release 223 ID# 0-58414U4500L450S0V35) with ESMTP id net; Wed, 7 Sep 2005 14:38:35 -0700 Received: from localhost (localhost [127.0.0.1]) by wolf.pjkh.com (Postfix) with ESMTP id 961F15856; Wed, 7 Sep 2005 14:38:31 -0700 (PDT) Received: from wolf.pjkh.com ([127.0.0.1]) by localhost (wolf.pjkh.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 22147-04; Wed, 7 Sep 2005 14:38:31 -0700 (PDT) Received: by wolf.pjkh.com (Postfix, from userid 1000) id 4551A5855; Wed, 7 Sep 2005 14:38:31 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by wolf.pjkh.com (Postfix) with ESMTP id 3E7CA5853; Wed, 7 Sep 2005 14:38:31 -0700 (PDT) Date: Wed, 7 Sep 2005 14:38:31 -0700 (PDT) From: Philip Hallstrom To: Roger Tannous Cc: pgsql-sql@postgresql.org Subject: Re: column names, types, properties for a table In-Reply-To: <20050907212543.88525.qmail@web51901.mail.yahoo.com> Message-ID: <20050907143715.Y22645@wolf.pjkh.com> References: <20050907212543.88525.qmail@web51901.mail.yahoo.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: by amavisd-new at pjkh.com X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=-0.051 required=5 tests=[AWL=-0.051] X-Spam-Level: X-Archive-Number: 200509/78 X-Sequence-Number: 22625 > Is it possible to issue an SQL query that lists column names, types (int, > varchar, boolean, etc.), properties (like NOT NULL or UNIQUE) > for a given table name ? Start psql with the -E option. Then "\d yourtable". It will print out the queries that are run internally to show you the table info... for example: % psql -E cc_8004 Welcome to psql 7.4.2, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help on internal slash commands \g or terminate with semicolon to execute query \q to quit cc_8004=# \d rep_general; ********* 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 pg_catalog.pg_table_is_visible(c.oid) AND c.relname ~ '^rep_general$' ORDER BY 2, 3; ************************** ********* QUERY ********** SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules FROM pg_catalog.pg_class WHERE oid = '21548032' ************************** ********* QUERY ********** SELECT a.attname, pg_catalog.format_type(a.atttypid, a.atttypmod), (SELECT substring(d.adsrc 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 = '21548032' AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum ************************** ********* QUERY ********** SELECT c2.relname, i.indisprimary, i.indisunique, pg_catalog.pg_get_indexdef(i.indexrelid) FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i WHERE c.oid = '21548032' AND c.oid = i.indrelid AND i.indexrelid = c2.oid ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname ************************** ********* QUERY ********** SELECT c.relname FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i WHERE c.oid=i.inhparent AND i.inhrelid = '21548032' ORDER BY inhseqno ASC ************************** Table "public.rep_general" Column | Type | Modifiers -------------------------+-----------------------------+-------------------- id | integer | not null loc_id | integer | not null dt | timestamp without time zone | not null num_active_visits | integer | not null default 0 num_passive_visits | integer | not null default 0 min_visit_length | integer | not null default 0 max_visit_length | integer | not null default 0 total_visit_length | integer | not null default 0 total_time_before_touch | integer | not null default 0 total_time_of_touch | integer | not null default 0 num_coupons_printed | integer | not null default 0 num_passive_promos | integer | not null default 0 num_active_promos | integer | not null default 0 Indexes: "rep_general_pk" primary key, btree (id) "rep_general_dt_idx" btree (dt) "rep_general_loc_id_idx" btree (loc_id) cc_8004=#