E2 temporal codecs — date / time / timestamp / interval.
PostgreSQL stores every temporal value relative to its own epoch,
2000-01-01 00:00:00, not the Unix epoch. The binary wire layouts are fixed-width
big-endian integers (no length-prefix here — these codecs see the column bytes the
framer already sliced out of aDataRow):
============ =========================================================== ===================
OID binary layout Python type
============ =========================================================== ===================
date 1082int32 days since 2000-01-01 date
time 1083int64 microseconds since midnight time
timestampint64 microseconds since 2000-01-01 00:00:00 (no tz) naive datetime
1114
timestamptzint64 microseconds since 2000-01-01 00:00:00 UTC aware datetime(UTC)
1184
timetz 1266int64 micros since midnight + int32 zone-offset secs aware time
intervalint64 micros + int32 days + int32 months timedelta or Interval
1186
============ =========================================================== ===================
Infinity.timestamp / timestamptz reserve the two extreme int64values for
±infinity: 0x7fff_ffff_ffff_ffff is +infinity and -0x8000_0000_0000_0000is
-infinity. Python's datetimecannot represent an unbounded instant, so
pelt maps them tomax / min(the saturating
sentinels asyncpg also offers via itsInfinityflag). The mapping is bijective on the
wire — encodingdatetime.max / datetime.minre-emits the infinity ints — so a
round-trip through these codecs is lossless.timestamptzreturns the aware UTC analogues
(max/min re-tagged with utc).
Interval. PostgreSQL's interval has three independent fields (months, days, micros) because
a month is not a fixed number of days.timedeltacan only carry days+micros,
so a months-bearing interval is decoded to a small frozenIntervalvalue object that
keeps all three fields; a months-free interval decodes to a plaintimedelta
for ergonomics (this matches asyncpg, which returnstimedelta whenever months == 0).
to_timedelta() is offered for callers that accept the "1 month == 30 days"
approximation explicitly.
Text codecs parse/format the ISO-ish forms PostgreSQL emits (2000-01-01,
12:34:56.789, 2000-01-01 12:34:56.789+00, P…-free H:M:Sintervals); they are a
fallback for servers that hand back the text format and are intentionally narrower than the
binary path. Live-PG parity for the full text-format surface (e.g.BCeras, non-ISO
DateStylesettings) is deferred to E4/E6 integration.
Faults raise pelt'sProtocolError (a PELT_*
code + hint), never a bare exception: every binary decoder length-guards its fixed-width
column beforeunpack(), so a truncated/garbled column is reported as the
malformed-wire desync it is rather than leaking an uncodederroracross the
driver boundary.TypeError / ValueErrorare reserved for programmer misuse of an
encode path (wrong Python type, naivetimetz), mirroring _builder.frame().
This module is sans-I/O: stdlib only (struct, datetime), no socket, no anyio.
data.drivers._pelt._codecs_temporal
| Name | Type | Default | Description |
|---|---|---|---|
type
|
|
— | |
qualified_name
|
|
— | |
element_type
|
|
— | |
description
|
|
— | |
source_file
|
|
— | |
line_number
|
|
— | |
is_autodoc
|
|
— | |
autodoc_element
|
|
— | |
_autodoc_template
|
|
— | |
_autodoc_url_path
|
|
— | |
_autodoc_page_type
|
|
— | |
title
|
|
— | |
doc_content_hash
|
|
— |
Symbols on this page
A PostgreSQLintervalwith its three independent fields preserved.
PostgreSQL keepsmonths, days and microsecondsseparately because a month and a day are…
Normalise atimedelta or Intervalto the wire triple.
Length-guard a fixed-width column beforeunpack().
A short/long column is the malformed-wire desync caseProtocolErrorexists to
signal — a rawerroris…
Alias of_dt.datetime.max
Alias of_dt.datetime.min
Interval
class
A PostgreSQLintervalwith its three independent fields preserved.
PostgreSQL keepsmonths, days and microsecondsseparately because a month and
a day are not fixed durations; collapsing them loses information. A months-free interval
decodes to a plaintimedelta instead — Intervalis only used
whenmonths != 0.
_interval_to_micros_days_months
function
def _interval_to_micros_days_months(value: Any) -> tuple[int, int, int]
Normalise atimedelta or Intervalto the wire triple.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value
|
Any
|
— |
_checked_unpack
function
def _checked_unpack(packer: struct.Struct, kind: str, data: bytes) -> tuple[Any, ...]
Length-guard a fixed-width column beforeunpack().
A short/long column is the malformed-wire desync caseProtocolErrorexists to
signal — a rawerroris an uncoded stdlib exception that would leak across
the driver boundary unpicklable-as-PeltError and without a PELT_*code or hint.
Mirrors the explicitlen() check + hint in the uuid / numericsibling codecs.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
packer
|
struct.Struct
|
— | |
kind
|
str
|
— | |
data
|
bytes
|
— |
_DT_MAX_NAIVE
alias
Alias of_dt.datetime.max
_DT_MIN_NAIVE
alias
Alias of_dt.datetime.min