Type Mapping¶
The following table shows the mapping between Python types and PostgreSQL types, and vice versa.
If pg8000 doesn’t recognize a type that it receives from PostgreSQL, it will
return it as a str
type. This is how pg8000 handles PostgreSQL enum
and
XML types.
Python Type |
PostgreSQL Type |
Notes |
---|---|---|
|
bool |
|
|
int4 |
|
|
numeric |
Python 2 only. |
|
text (Python 3) bytea (Python 2) |
|
|
text |
Python 2 only. |
|
float8 |
|
|
numeric |
|
bytea |
Python 2 only. |
|
|
bytea |
Python 3 only. |
|
timestamp without time zone |
|
|
timestamp with time zone |
|
|
date |
|
|
time without time zone |
|
|
interval |
datetime.timedelta is used unless the interval has months, in which case pg8000.Interval is used |
None |
NULL |
|
|
uuid |
|
|
inet |
Python 3.3 onwards |
|
inet |
Python 3.3 onwards |
|
inet |
Python 3.3 onwards |
|
inet |
Python 3.3 onwards |
|
xid |
|
list of |
INT4[] |
|
list of |
FLOAT8[] |
|
list of |
BOOL[] |
|
list of |
TEXT[] |
|
list of |
TEXT[] |
Python 2 only. |
list of |
int2vector |
Only from PostgreSQL to Python |
JSON |
json, jsonb |
JSON string as an SQL parameter. Results returned as de-serialized JSON. |