Re: [INTERFACES] Determine data type of columns
От | darcy@druid.net (D'Arcy J.M. Cain) |
---|---|
Тема | Re: [INTERFACES] Determine data type of columns |
Дата | |
Msg-id | m0zdMGE-0000eRC@druid.net обсуждение исходный текст |
Ответ на | Determine data type of columns ("Bryan White" <bryan@arcamax.com>) |
Список | 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 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.
В списке pgsql-interfaces по дате отправления: