X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 76843D1B23B for ; Sun, 16 May 2004 22:18:38 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 90722-07 for ; Sun, 16 May 2004 22:18:17 -0300 (ADT) Received: from mail.bundaberg.qld.gov.au (unknown [203.30.176.2]) by svr1.postgresql.org (Postfix) with ESMTP id 9A512D1B1C7 for ; Sun, 16 May 2004 22:18:08 -0300 (ADT) Received: from bundaberg.qld.gov.au (dev.bundabergcity.qld.gov.au [172.16.3.82]) by mail.bundaberg.qld.gov.au (8.12.8/8.12.8) with ESMTP id i4H1I8pF028056 for ; Mon, 17 May 2004 11:18:08 +1000 Message-ID: <40A81355.8060703@bundaberg.qld.gov.au> Date: Mon, 17 May 2004 11:20:21 +1000 From: Stefan Gastaldon User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7b) Gecko/20040421 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-php@postgresql.org Subject: Re: table column information References: <1084749506.2056.148.camel@lathe> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-MailScanner-Information: Please contact Clayton for more information X-MailScanner: Found to be clean X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200405/42 X-Sequence-Number: 2761 ljb wrote: >webid@cfl.rr.com wrote: > > >>Currently using Postgresql 7.2.4-5.80 with php 4.2.2.-8.0.8 on a redhat >>8.0 system. >> >>I am writing some php scripts where I want to generate a list of the >>column names in a particular table that the user selects. I could take >>the brute force method and hard code the column names but then every >>time I add a new table or modify an existing one I would have to modify >>the code. What I want is to have a generic function that given the >>table name it will pull the column names for my use. >> >>I need to get the table column names for several tables I have setup. I >>know if I do a select * from tablename I can then use the pg_fieldname >>function to pull the column names for all columns. >> >>But I don't think I want to select the entire contents of the table >>every time I want to get the names of the columns. I know this will >>work but I think performance will be very poor. >>... >> >> > >You almost got it - just do "select * from tablename where 0=1", which returns >no rows but will give you the fieldnames. A portable and (I think) >efficient way to get table column names. > >---------------------------(end of broadcast)--------------------------- >TIP 6: Have you searched our list archives? > > http://archives.postgresql.org > > even more efficient (possibly not quite as portable but does work with pgsql and mysql) select * from tablename limit 0