Re: table column information

From: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
To: "Scot L(dot) Harris" <webid(at)cfl(dot)rr(dot)com>, pgsql-php(at)postgresql(dot)org
Subject: Re: table column information
Date: 2004-05-17 17:47:49
Message-ID: 200405171047.49867.scrawford@pinpointresearch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

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

In response to

Browse pgsql-php by date

  From Date Subject
Next Message Scot L. Harris 2004-05-17 21:31:44 Re: table column information
Previous Message Paul Lynch 2004-05-17 12:21:00 Re: Parsing Data, Table to Form