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

Re: [INTERFACES] Determine data type of columns

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Bryan White" <bryan(at)arcamax(dot)com>
Cc: pgsql-interfaces(at)postgreSQL(dot)org
Subject: Re: [INTERFACES] Determine data type of columns
Date: 1998-11-10 23:19:30
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces
"Bryan White" <bryan(at)arcamax(dot)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
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

pgsql-interfaces by date

Next:From: Ken J. WrightDate: 1998-11-11 00:38:02
Subject: how to obtain column info
Previous:From: D'Arcy J.M. CainDate: 1998-11-10 22:27:41
Subject: Re: [INTERFACES] Determine data type of columns

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