From: ljb <ljb220@mindspring.com>
To: pgsql-php@postgresql.org
Subject: Re: table column information
Date: Mon, 17 May 2004 00:19:20 +0000 (UTC)
Message-ID: <c890e8$12ql$1@news.hub.org> (raw)
References: <1084749506.2056.148.camel@lathe>
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.
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: ljb220@mindspring.com
Subject: Re: table column information
In-Reply-To: <c890e8$12ql$1@news.hub.org>
References: <1084749506.2056.148.camel@lathe> <c890e8$12ql$1@news.hub.org>
* 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