Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id BC287476063 for ; Wed, 6 Nov 2002 03:00:09 -0500 (EST) Received: from kant.catalyst.net.nz (203-79-74-78.adsl.paradise.net.nz [203.79.74.78]) by postgresql.org (Postfix) with ESMTP id 6877A475FD4 for ; Wed, 6 Nov 2002 03:00:08 -0500 (EST) Received: from 127.0.0.1 (ident=unknown) by kant.catalyst.net.nz with esmtp (masqmail 0.2.14) id 189L6a-2Nj-00; Wed, 06 Nov 2002 21:00:04 +1300 Subject: Re: Column names From: Andrew McMillan To: Kelvin Varst Cc: pgsql-php@postgresql.org In-Reply-To: References: Content-Type: text/plain Organization: Message-Id: <1036569603.8328.23.camel@kant.mcmillan.net.nz> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.1.90 (Preview Release) Date: 06 Nov 2002 21:00:03 +1300 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/11 X-Sequence-Number: 1593 On Sun, 2002-11-03 at 22:26, Kelvin Varst wrote: > Hi, > > When I make a simple "SELECT * FROM table;" query, is there somewhere in > that query I can find the names of the columns? In PHP if you get the rows with: $row = pg_Fetch_Object( $result, $rownum); You will be able to refer to them by name as $row->fieldname $row->otherfield and so on. This is very useful :-) Otherwise, if you want to know the column names, something like: SELECT attname FROM pg_attribute WHERE attrelid = (SELECT oid FROM pg_class WHERE relname = 'mytable') AND attnum > 0 ORDER BY attnum; will get them for you. Regards, Andrew. -- --------------------------------------------------------------------- Andrew @ Catalyst .Net.NZ Ltd, PO Box 11-053, Manners St, Wellington WEB: http://catalyst.net.nz/ PHYS: Level 2, 150-154 Willis St DDI: +64(4)916-7201 MOB: +64(21)635-694 OFFICE: +64(4)499-2267 Survey for nothing with http://survey.net.nz/ ---------------------------------------------------------------------