pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: darcy@druid.net
To: bryan@arcamax.com
Cc: pgsql-interfaces@postgreSQL.org
Subject: Re: [INTERFACES] Determine data type of columns
Date: Tue, 10 Nov 1998 17:27:41 -0500 (EST)
Message-ID: <m0zdMGE-0000eRC@druid.net> (raw)
In-Reply-To: <012001be0cf0$131ffb60$a3f0f6ce@bryan.arcamax.com>

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
    http://www.druid.net/pygresql/

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@{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.



view thread (4+ messages)  latest in thread

Message-ID: <m0zdMGE-0000eRC@druid.net>
Permalink:  ../m0zdMGE-0000eRC@druid.net/
Also on:    postgresql.org/message-id/m0zdMGE-0000eRC@druid.net

 · 

reply

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: darcy@druid.net, bryan@arcamax.com
  Subject: Re: [INTERFACES] Determine data type of columns
  In-Reply-To: <m0zdMGE-0000eRC@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