Data types¶
Note
The type that date and datetime objects are mapped to, depends on the
CrateDB column type.
Note
When using date or datetime objects with timezone information,
the value is implicitly converted to a Unix time (epoch) timestamp, i.e.
the number of seconds which have passed since 00:00:00 UTC on
Thursday, 1 January 1970.
This means, when inserting or updating records using timezone-aware Python
date or datetime objects, timezone information will not be
preserved. If you need to store it, you will need to use a separate column.
Note
Inserting timezone-aware datetime objects is supported; the value is
converted to a UTC instant on the way in, as outlined above. On the way
out, the dialect returns naive datetime objects in UTC by default.
To read values back as timezone-aware datetime objects instead,
configure the CrateDB driver’s time_zone argument, for example:
from sqlalchemy import create_engine
engine = create_engine(
"crate://localhost:4200",
connect_args={"time_zone": "+0530"},
)
The driver then converts TIMESTAMP columns to timezone-aware
datetime objects transparently. See TIMESTAMP conversion with time
zone in the driver documentation for the accepted time_zone values.
SQLAlchemy¶
This section documents data types for the CrateDB SQLAlchemy dialect.
Type map¶
The CrateDB dialect maps between data types like so:
CrateDB |
SQLAlchemy |
|---|---|
|
|
ObjectType (extension type) |
|
|
|
|
|
ObjectArray (extension type) |
|
Geopoint and Geoshape (extension type) |
|
Geopoint and Geoshape (extension type) |