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

Re: [INTERFACES] Determine data type of columns

From: darcy(at)druid(dot)net (D'Arcy J(dot)M(dot) Cain)
To: bryan(at)arcamax(dot)com (Bryan White)
Cc: pgsql-interfaces(at)postgreSQL(dot)org
Subject: Re: [INTERFACES] Determine data type of columns
Date: 1998-11-10 22:27:41
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces
Thus spake Bryan White
> 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)?
> Do I have to execute another query to determine the actual type?
> 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?

Look at how I do it in PyGreSQL.  The code is available at

First, I run this Python script to get the proper OIDs.

#! /usr/local/bin/python

import string

# change this if you have it somewhere else
for l in open("/usr/local/pgsql/src/include/catalog/pg_type.h").readlines():
        tokens = string.split(l)
        if len(tokens) == 0 or tokens[0] != "#define": continue

        if tokens[1] in ('CASHOID', 'INT2OID', 'INT4OID', 'OIDOID', 'FLOAT4OID', 'FLOAT8OID'):
                print l,

This gets me my #defines.  My assumption is that if it isn't one of those
then I just treat it as text.  I include this in my C source with a
comment about how naughty I am.  Then I use these values in the functions
that have to do the conversions.

D'Arcy J.M. Cain <darcy(at){druid|vex}.net>   |  Democracy is three wolves                |  and a sheep voting on
+1 416 424 2871     (DoD#0082)    (eNTP)   |  what's for dinner.

In response to

pgsql-interfaces by date

Next:From: Tom LaneDate: 1998-11-10 23:19:30
Subject: Re: [INTERFACES] Determine data type of columns
Previous:From: Bryan WhiteDate: 1998-11-10 21:21:26
Subject: Determine data type of columns

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