Re: [INTERFACES] Determine data type of columns
От | Tom Lane |
---|---|
Тема | Re: [INTERFACES] Determine data type of columns |
Дата | |
Msg-id | 6735.910739970@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | Determine data type of columns ("Bryan White" <bryan@arcamax.com>) |
Список | pgsql-interfaces |
"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
В списке pgsql-interfaces по дате отправления: