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 BF278D1B1D0 for ; Mon, 17 May 2004 14:48:14 -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 94198-07 for ; Mon, 17 May 2004 14:47:51 -0300 (ADT) Received: from polaris.pinpointresearch.com (66-7-238-130.cust.telepacific.net [66.7.238.130]) by svr1.postgresql.org (Postfix) with ESMTP id EFF8ED1B19C for ; Mon, 17 May 2004 14:47:49 -0300 (ADT) Received: from betelgeuse.pinpointresearch.com (betelgeuse.pinpointresearch.com [192.168.1.179]) by polaris.pinpointresearch.com (Postfix) with ESMTP id 763D5103CA; Mon, 17 May 2004 10:47:50 -0700 (PDT) From: Steve Crawford Organization: Pinpoint Research To: "Scot L. Harris" , pgsql-php@postgresql.org Subject: Re: table column information Date: Mon, 17 May 2004 10:47:49 -0700 User-Agent: KMail/1.5.1 References: <1084749506.2056.148.camel@lathe> <1084762532.4822.36.camel@lamb.mcmillan.net.nz> <1084763775.2058.173.camel@lathe> In-Reply-To: <1084763775.2058.173.camel@lathe> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200405171047.49867.scrawford@pinpointresearch.com> 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/32 X-Sequence-Number: 2751 On Sunday 16 May 2004 8:16 pm, Scot L. Harris wrote: > On Sun, 2004-05-16 at 22:55, Andrew McMillan wrote: > > On Mon, 2004-05-17 at 00:19 +0000, ljb wrote: > > > > 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. > > > > It can be a cute trick, and I use it myself from time to time > > (especially for "CREATE TABLE AS SELECT ..." where I want an > > empty table with the same structure, pre v 7.4 which can do this > > anyway). You should be aware however that as written above it > > will almost invariably force a full-table scan! Depending on your needs you can also use: select * from tablename limit 0; Slow machine, 3.3 million row table: 4 milliseconds. No full table scan there. Cheers, Steve