Data Types¶
pgcopy supports a wide range of PostgreSQL scalar data types.
Database null must be represented in python as None.
Scalars¶
PostgreSQL type |
Python type |
Notes |
|---|---|---|
bool |
bool |
|
smallint |
int |
|
integer |
int |
|
bigint |
int |
|
real |
float |
|
double precision |
float |
|
char |
str, bytes |
|
varchar |
str, bytes |
|
text |
str, bytes |
|
bytea |
bytes |
|
enum types |
str, bytes |
|
date |
datetime.date |
|
time |
datetime.time |
|
timestamp |
datetime.datetime |
|
timestamp with time zone |
datetime.datetime |
|
numeric |
decimal.Decimal |
|
json |
str, bytes |
|
jsonb |
bytes |
|
uuid |
str, uuid.UUID |
|
list[float] |
Arrays¶
As of v1.4.0, all of the supported scalar types may be used in array types as well.
Encoding¶
As of v1.4, encoding of unicode strings is handled automatically for char,
varchar, text, and json PostgreSQL types. Python bytes may also be
used, provided the encoding matches that of the db connection.
No encoding is performed for data to be inserted into bytea or
jsonb types.
Truncation¶
Where database columns have a fixed length, string data will be silently truncated to fit.
Numeric¶
PostgreSQL numeric does not support Decimal('Inf') or
Decimal('-Inf'). pgcopy serializes these as NaN.
Contrib¶
Support for vector type from pgvector is available in
contrib.vector.CopyManager.