Received: from sss.sss.pgh.pa.us (sss.pgh.pa.us [209.114.166.2]) by hub.org (8.9.3/8.9.3) with ESMTP id RAA07965 for ; Mon, 13 Dec 1999 17:51:19 -0500 (EST) (envelope-from tgl@sss.pgh.pa.us) Received: from sss.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.sss.pgh.pa.us (8.9.1/8.9.1) with ESMTP id RAA12858; Mon, 13 Dec 1999 17:50:47 -0500 (EST) To: "Steven M. Wheeler" cc: pgsql-sql@hub.org Subject: Re: [SQL] How do I get column names? In-reply-to: Your message of Mon, 13 Dec 1999 14:30:07 -0600 <3855574F.3314738E@sabre.com> Date: Mon, 13 Dec 1999 17:50:47 -0500 Message-ID: <12856.945125447@sss.pgh.pa.us> From: Tom Lane "Steven M. Wheeler" writes: > What is the best way to query the DB, to get the column names for a > particular table? Usually you'd join across pg_attribute and pg_class, assuming that you were starting from a table name. For example: regression=> select attname, attnum from pg_attribute, pg_class where regression-> attrelid = pg_class.oid and relname = 'int8_tbl'; attname|attnum -------+------ cmax | -6 xmax | -5 cmin | -4 xmin | -3 oid | -2 ctid | -1 q1 | 1 q2 | 2 (8 rows) You probably would also want 'and attnum > 0' in the where-clause to exclude the system attributes... regards, tom lane