Skip site navigation (1) Skip section navigation (2)

Re: table column information

From: Stefan Gastaldon <stefang(at)bundaberg(dot)qld(dot)gov(dot)au>
To: pgsql-php(at)postgresql(dot)org
Subject: Re: table column information
Date: 2004-05-17 01:20:21
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-php

ljb wrote:

>webid(at)cfl(dot)rr(dot)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?
even more efficient (possibly not quite as portable but does work with 
pgsql and mysql)

select * from tablename limit 0

In response to

pgsql-php by date

Next:From: Scot L. HarrisDate: 2004-05-17 01:35:32
Subject: Re: table column information
Previous:From: ljbDate: 2004-05-17 00:19:20
Subject: Re: table column information

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group