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 DEF20D1CAB0 for ; Sun, 16 May 2004 21:49:03 -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 88276-03 for ; Sun, 16 May 2004 21:48:47 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id C8884D1F0A6 for ; Sun, 16 May 2004 21:48:43 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id i4H0mhSx082731 for ; Mon, 17 May 2004 00:48:43 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id i4H0JKF1052496 for pgsql-php@postgresql.org; Mon, 17 May 2004 00:19:20 GMT From: ljb X-Newsgroups: comp.databases.postgresql.interfaces.php Subject: Re: table column information Date: Mon, 17 May 2004 00:19:20 +0000 (UTC) Organization: Hub.Org Networking Services Lines: 23 Message-ID: References: <1084749506.2056.148.camel@lathe> X-Complaints-To: usenet@news.hub.org X-No-Archive: yes User-Agent: slrn/0.9.8.0 (Linux) To: pgsql-php@postgresql.org X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.9 tagged_above=0.0 required=5.0 tests=FROM_ENDS_IN_NUMS X-Spam-Level: X-Archive-Number: 200405/26 X-Sequence-Number: 2745 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.