From: Billy G. A. <bil...@mu...> - 2003-04-30 01:06:29
|
Benjamin Scherrey wrote: >Ah... thanx Bill. Now I'm trying to figure out how to identify that it's a numeric type from the >description. I know the right field to compare (description[1]), just not how to make the >comparison... hazzards of weak-typed languages I guess. I know this is gonna be one of those >stupidly easy things... > > > The following objects are defined in PgSQL: BINARY PostgreSQL binary types (OID, Large Objects, BYTEA) DATETIME PostgreSQL date/time types (DATE, TIME, etc.) NUMBER PostgreSQL numeric types (INT2, INT, INT8, FLOAT8, etc) ROWID PostgreSQL types representing row IDs, etc. STRING PostgreSQL text types (CHAR, VARCHAR, TEXT, etc.) BOOLEAN PostgreSQL boolean type. OTHER PostgreSQL types not catagorized above. You can do an comparison to the above types to get the information you want. For example: Python 2.2.2 (#7, Nov 27 2002, 17:10:05) [C] on openunix8 Type "help", "copyright", "credits" or "license" for more information. >>> from pyPgSQL import PgSQL >>> cx = PgSQL.connect(password='XXXXXXXXXX') >>> cu = cx.cursor() >>> cu.execute('select * from a') >>> for i in cu.description: ... print i ... ['id', integer, None, 4, None, None, None, 0] ['i', integer, None, 4, None, None, None, 0] ['s', text, None, -1, None, None, None, 0] >>> if cu.description[0][1] == PgSQL.NUMBER: ... print 'NUMBER' ... else: ... print 'Not a NUMBER' ... NUMBER >>> if cu.description[2][1] == PgSQL.NUMBER: ... print 'NUMBER' ... else: ... print 'Not a NUMBER' ... Not a NUMBER >>> I hope this helps. Later. -- ___________________________________________________________________________ ____ | Billy G. Allie | Domain....: Bil...@mu... | /| | 7436 Hartwell | MSN.......: B_G...@em... |-/-|----- | Dearborn, MI 48126| |/ |LLIE | (313) 582-1540 | |