pgdbType – Type objects and constructors¶
Type constructors¶
For binding to an operation’s input parameters, PostgreSQL needs to have
the input in a particular format. However, from the parameters to the
pgdbCursor.execute() and pgdbCursor.executemany() methods it
is not always obvious as which PostgreSQL data types they shall be bound.
For instance, a Python string could be bound as a simple char value,
or also as a date or a time. To make the intention clear in such
cases, you can wrap the parameters in type helper objects. PyGreSQL provides
the constructors defined below to create such objects that can hold special
values. When passed to the cursor methods, PyGreSQL can then detect the
proper type of the input parameter and bind it accordingly.
The pgdb module exports the following type constructors as part of
the DB-API 2 standard:
-
pgdb.Date(year, month, day)¶ Construct an object holding a date value
-
pgdb.Time(hour, minute=0, second=0, microsecond=0)¶ Construct an object holding a time value
-
pgdb.Timestamp(year, month, day, hour=0, minute=0, second=0, microsecond=0)¶ Construct an object holding a time stamp value
-
pgdb.DateFromTicks(ticks)¶ Construct an object holding a date value from the given ticks value
-
pgdb.TimeFromTicks(ticks)¶ Construct an object holding a time value from the given ticks value
-
pgdb.TimestampFromTicks(ticks)¶ Construct an object holding a time stamp from the given ticks value
-
pgdb.Binary(bytes)¶ Construct an object capable of holding a (long) binary string value
Note
SQL NULL values are always represented by the Python None singleton
on input and output.
Type objects¶
-
class
pgdb.pgdbType¶
The pgdbCursor.description attribute returns information about each
of the result columns of a query. The type_code must compare equal to one
of the pgdbType objects defined below. Type objects can be equal to
more than one type code (e.g. DATETIME is equal to the type codes
for date, time and timestamp columns).
The pgdb module exports the following Type objects as part of the
DB-API 2 standard:
-
STRING Used to describe columns that are string-based (e.g.
char,varchar,text)
-
BINARY Used to describe (long) binary columns (
bytea)
-
NUMBER Used to describe numeric columns (e.g.
int,float,numeric,money)
-
DATETIME Used to describe date/time columns (e.g.
date,time,timestamp,interval)
-
ROWID Used to describe the
oidcolumn of PostgreSQL database tables
Note
The following more specific type objects are not part of the DB-API 2 standard.
-
BOOL Used to describe
booleancolumns
-
SMALLINT Used to describe
smallintcolumns
-
INTEGER Used to describe
integercolumns
-
LONG Used to describe
bigintcolumns
-
FLOAT Used to describe
floatcolumns
-
NUMERIC Used to describe
numericcolumns
-
MONEY Used to describe
moneycolumns
-
DATE Used to describe
datecolumns
-
TIME Used to describe
timecolumns
-
TIMESTAMP Used to describe
timestampcolumns
-
INTERVAL Used to describe date and time
intervalcolumns