From swheeler@sabre.com Mon Dec 13 20:34:19 1999 Received: from mailgate1.sabre.com (mailgate1.sabre.com [199.100.49.125]) by hub.org (8.9.3/8.9.3) with ESMTP id PAA80417 for ; Mon, 13 Dec 1999 15:34:19 -0500 (EST) (envelope-from swheeler@sabre.com) Received: from pop3.sabre.com (pop3.sabre.com [144.9.112.62]) by mailgate1.sabre.com (8.9.3/8.9.3) with ESMTP id OAA09599 for ; Mon, 13 Dec 1999 14:30:19 -0600 (CST) Received: from sabre.com ([172.29.63.42]) by pop3.sabre.com (Netscape Messaging Server 3.6) with ESMTP id AAA6481 for ; Mon, 13 Dec 1999 14:30:14 -0600 Sender: smw@sabre.com Message-ID: <3855574F.3314738E@sabre.com> Date: Mon, 13 Dec 1999 14:30:07 -0600 From: "Steven M. Wheeler" Organization: Mid-range UNIX Engineering, The SABRE Group X-Mailer: Mozilla 4.7 [en] (X11; I; Linux 2.2.13 i686) X-Accept-Language: en MIME-Version: 1.0 To: pgsql-sql@hub.org Subject: How do I get column names? References: <199911050400.XAA57002@hub.org> Content-Type: multipart/alternative; boundary="------------FD61CE605FCC0B1B79878DEA" --------------FD61CE605FCC0B1B79878DEA Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit A simple question. What is the best way to query the DB, to get the column names for a particular table? Thanks! -- Steven Wheeler Mid-Range UNIX Engineering Sabre Inc. (918) 292-4119 --------------FD61CE605FCC0B1B79878DEA Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit A simple question.

What is the best way to query the DB, to get the column names for a particular table?

Thanks!

-- 
Steven Wheeler
Mid-Range UNIX Engineering
Sabre Inc.
(918) 292-4119
  --------------FD61CE605FCC0B1B79878DEA-- From tgl@sss.pgh.pa.us Mon Dec 13 22:51:19 1999 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 From neko@kredit.sth.szif.hu Tue Dec 14 01:15:27 1999 Received: from kredit.sth.szif.hu (IDENT:neko@kredit.sth.szif.hu [193.224.129.23]) by hub.org (8.9.3/8.9.3) with ESMTP id UAA42045 for ; Mon, 13 Dec 1999 20:15:27 -0500 (EST) (envelope-from neko@kredit.sth.szif.hu) From: neko@kredit.sth.szif.hu Received: from localhost (neko@localhost) by kredit.sth.szif.hu (8.9.3/8.9.3) with ESMTP id CAA05935; Tue, 14 Dec 1999 02:13:12 +0100 Date: Tue, 14 Dec 1999 02:13:12 +0100 (CET) To: "Steven M. Wheeler" cc: pgsql-sql@hub.org Subject: Re: [SQL] How do I get column names? In-Reply-To: <3855574F.3314738E@sabre.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Mon, 13 Dec 1999, Steven M. Wheeler wrote: > A simple question. > > What is the best way to query the DB, to get the column names for a > particular table? SELECT attname FROM pg_attribute, pg_class WHERE pg_class.oid = attrleid AND attnum>0 AND relname = 'particular_table'; In this way, in each tuple of the result can find a column name. Or can use the simple: SELECT * FROM particular_table LIMIT 1; This query will be return with a single line, and you can get the column names from the result. (PQfname). The first way may a bit faster, but the second can work with user typed querys too. Best Regards -- nek;(