From: Tom Lane <tgl@sss.pgh.pa.us>
To: Bryan White <bryan@arcamax.com>
Cc: pgsql-interfaces@postgreSQL.org
Subject: Re: [INTERFACES] Determine data type of columns
Date: Tue, 10 Nov 1998 18:19:30 -0500
Message-ID: <6735.910739970@sss.pgh.pa.us> (raw)
In-Reply-To: <012001be0cf0$131ffb60$a3f0f6ce@bryan.arcamax.com>
"Bryan White" <bryan@arcamax.com> writes:
> This brings me to my question. The PQftype function returns an OID but I
> don't see any documentation on how to interpret it. Are the values constant
> for the built in types (specifically int4, text, and date)?
The OID for a type is the OID of the row for the type in the system
table pg_type. Try
select oid,* from pg_type;
and much will become clear. You can go from type name to OID and
vice versa with appropriate queries on pg_type.
OIDs for the system-defined types should be the same across all
installations. OIDs for user-defined types are likely to change
if you initdb and reload the database.
> Is there a way to encode the values in an insert/update statement such that
> they will be quietly converted to the proper type on the backend?
You should be able to do something like
'42'::int4
for any standard type --- they all have string-to-datatype converters.
The parser essentially does the above for you when it sees an unadorned
42. It will also supply a free conversion from string literal to
most of the more complicated types (datetime, for instance). I imagine
that as an error-detection measure it will not supply a free
string-to-int or string-to-float conversion --- you have to write the
cast if you want a string literal to be read as an int or float.
regards, tom lane
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 using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: tgl@sss.pgh.pa.us, bryan@arcamax.com
Subject: Re: [INTERFACES] Determine data type of columns
In-Reply-To: <6735.910739970@sss.pgh.pa.us>
* 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