pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Steve Crawford <scrawford@pinpointresearch.com>
To: Scot L. Harris <webid@cfl.rr.com>
To: pgsql-php@postgresql.org
Subject: Re: table column information
Date: Mon, 17 May 2004 10:47:49 -0700
Message-ID: <200405171047.49867.scrawford@pinpointresearch.com> (raw)
In-Reply-To: <1084763775.2058.173.camel@lathe>
References: <1084749506.2056.148.camel@lathe>
	<1084762532.4822.36.camel@lamb.mcmillan.net.nz>
	<1084763775.2058.173.camel@lathe>

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




view thread (11+ messages)  latest in thread

Message-ID: <200405171047.49867.scrawford@pinpointresearch.com>
Permalink:  ../200405171047.49867.scrawford@pinpointresearch.com/
Also on:    postgresql.org/message-id/200405171047.49867.scrawford@pinpointresearch.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: scrawford@pinpointresearch.com, webid@cfl.rr.com
  Subject: Re: table column information
  In-Reply-To: <200405171047.49867.scrawford@pinpointresearch.com>
  References: <1084749506.2056.148.camel@lathe> <1084762532.4822.36.camel@lamb.mcmillan.net.nz> <1084763775.2058.173.camel@lathe> <200405171047.49867.scrawford@pinpointresearch.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox