From: darcy@druid.net
To: glenn.sullivan@nmr.varian.com
Cc: pgsql-sql@hub.org
Subject: Re: [SQL] Getting datatype before SELECT
Date: Tue, 29 Sep 1998 22:10:44 -0400 (EDT)
Message-ID: <m0zOBj2-00006FC@druid.net> (raw)
In-Reply-To: <3611135E.491D2598@nmr.varian.com>
Thus spake Glenn Sullivan
> 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?
Here's a select statement I use to get the types of a class.
SELECT pg_attribute.attname, pg_type.typname
FROM pg_class, pg_attribute, pg_type
WHERE pg_class.relname = '%s' AND
pg_attribute.attnum > 0 AND
pg_attribute.attrelid = pg_class.oid AND
pg_attribute.atttypid = pg_type.oid
The "%s" gets replaced by the class name and the typname shows the
name of the type. Here's an example output.
attname |typname
---------+-------
ride_id |int4
name |text
from_date|date
to_date |date
contact |text
phone |text
email |text
url |text
(8 rows)
--
D'Arcy J.M. Cain <darcy@{druid|vex}.net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 424 2871 (DoD#0082) (eNTP) | what's for dinner.
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-sql@postgresql.org
Cc: darcy@druid.net, glenn.sullivan@nmr.varian.com, pgsql-sql@hub.org
Subject: Re: [SQL] Getting datatype before SELECT
In-Reply-To: <m0zOBj2-00006FC@druid.net>
References: <3611135E.491D2598@nmr.varian.com> <m0zOBj2-00006FC@druid.net>
* 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