Re: [SQL] Getting datatype before SELECT

From: David Hartwig <daveh(at)insightdist(dot)com>
To: Glenn Sullivan <glenn(dot)sullivan(at)nmr(dot)varian(dot)com>
Cc: pgsql-sql(at)hub(dot)org
Subject: Re: [SQL] Getting datatype before SELECT
Date: 1998-09-29 21:28:31
Message-ID: 361150FF.8FA8CB1F@insightdist.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Glenn Sullivan wrote:

> In my C code which communicates with the Postgres database,
> I have the need to determine the datatype of a column, before
> I have done a SELECT command. I have the name of the column,
> but I cannot seem to figure out how to get the datatype information
> until after I have done a SELECT. Then I can call PQfnumber() and
> PQftype() to get the type. Does anyone know how to do this?

-- will give you the attribute name

SELECT pg_type.typname FROM pg_class, pg_type, pg_attribute WHERE
pg_class.relname = 'your_table' AND
pg_attribute.attname = 'your_attribute' AND
pg_class.oid = pg_attribute.attrelid AND
pg_attribute.atttypid = pg_type.oid;

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message D'Arcy J.M. Cain 1998-09-30 02:10:44 Re: [SQL] Getting datatype before SELECT
Previous Message Glenn Sullivan 1998-09-29 17:05:34 Getting datatype before SELECT