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

Re: Building a list of fields ?

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: David(dot)Jacques(at)CCRS(dot)NRCan(dot)gc(dot)ca
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Building a list of fields ?
Date: 2005-01-19 18:20:01
Message-ID: 20050119182001.GA95507@winnie.fuhr.org (view raw or flat)
Thread:
Lists: pgsql-admin
On Wed, Jan 19, 2005 at 12:38:11PM -0500, David(dot)Jacques(at)CCRS(dot)NRCan(dot)gc(dot)ca wrote:

> I'm trying to make a generic function  InsertValues().
> 
> In order to do this (cleanly) I need to construct a field list from
> the table name passed in as an argument. However I see no libpq function
> to return the field names of a table. Does such a thing exist ?

I don't see a function that specifically returns a table's structure,
but you can use the functions listed under "Retrieving Query Result
Information" to inspect the results of a query against that table.

> I thought I was on to something by using the pg_attribute system table, 
>  but there is no field to relate a column to its table.

Yes there is -- attrelid is the table's OID.  You can join attrelid
with pg_class.oid.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

pgsql-admin by date

Next:From: Jonathan PoolDate: 2005-01-20 02:43:04
Subject: Postmaster stops after starting--solution
Previous:From: David.JacquesDate: 2005-01-19 17:38:11
Subject: Building a list of fields ?

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