Glossary#
Every PostgreSQL and pgdorm term used across The Elephant Dormitory, grouped by layer for quick lookup.
Schema & Modeling#
- CTI (Class-Table Inheritance)
- Polymorphic modeling where a shared base table (
task) holds common columns and each subtype (cleaning_task,maintenance_task) lives in its own joined table sharing the same primary key. Enabled viajoined=True. See Chapter 7. - Discriminator
- A column identifying which subtype a polymorphic row belongs to.
pgdormforbids string discriminators:pg.discriminator(...)must reference aTypeTableprimary key, and variants must beIntEnummembers. See Chapter 7. - Exclusion constraint /
WITHOUT OVERLAPS(GiST) - A native PostgreSQL temporal constraint (
PRIMARY KEY (room_id, stay WITHOUT OVERLAPS)orUNIQUE (... WITHOUT OVERLAPS)) backed by a GiST index (scalar key columns use thebtree_gistextension, which pgdorm installs for you) that forbids overlapping ranges for the same key. Violations raiseExclusionViolationError(23P01). See Chapter 6. - Partial index
- An index with a
WHEREpredicate (for exampleWHERE out_of_service IS FALSE) that indexes only the active subset of rows, staying smaller and faster. See Chapter 4. - RLS (Row-Level Security)
- Database-enforced per-row access policies (
USINGfor reads,WITH CHECKfor writes) evaluated inside PostgreSQL on every query. Paired withlocal_settings=inpgdormfor 1-RTT, PgBouncer-safe multi-tenancy. See Chapter 14. - STI (Single-Table Inheritance)
- Polymorphic modeling where all variants (
CardPayment,BankTransfer,VoucherPayment) live in one table guarded by aTypeTablediscriminator and auto-generated disjointCHECKconstraints. See Chapter 7. TypeDecorator- A reusable column codec subclassing
pg.TypeDecorator[PyT, DbT]that transforms values automatically on bind (process_bind_param) and hydration (process_result_value), such asLowerEmail. See Chapter 4. TypeTable- A small lookup table auto-generated and seeded from a Python
IntEnum, using anINTEGERPK and a uniquecodecolumn. Enforced by real foreign keys instead of raw strings. See Chapter 4. UNSET(pg.UNSET)- Sentinel distinguishing "field omitted in PATCH" from
None(deliberate SQLNULL). Prevents partial updates from wiping existing columns. See Chapter 2. UUIDv7(pg.uuidv7())- Time-ordered UUID built natively into PostgreSQL, combining unguessable public identifiers with B-tree index locality. See Chapter 4.
- Virtual generated column
- Default mode for
GENERATED ALWAYS AS (...) VIRTUALin PostgreSQL, computed on read with zero disk storage (Guest.full_name). Contrast withmode=pg.enums.GeneratedMode.STORED(Charge.amount). See Chapter 4.
Queries, Joins & Analytics#
- CTE (Common Table Expression)
- A named temporary result set inside a single SQL statement (
WITH ... AS (...)).pgdormsupports both standard CTEs, writable CTEs (used automatically for 1-RTT CTI inserts), and typedWITH RECURSIVECTEs withSEARCHandCYCLE. See Chapter 12. - Data-Modifying CTE (
WriteCte) - A PostgreSQL writable
WITHclause (WITH claimed AS (UPDATE ... RETURNING ...)) built viapg.write_cte(...)that executes a mutation and feeds itsRETURNINGrows directly into a downstreamSELECT,INSERT,UPDATE, orDELETEin a single statement. See Field Note 6. - Keyset pagination
- Cursor-based pagination using row-value comparisons such as
(last_name, guest_id) > ($1, $2)so page 10,000 hits a B-tree index in O(log N) time instead of scanning and discarding rows likeOFFSET. See Chapter 9. - Lateral Subquery (
Select.join_lateral) - A correlated
JOIN LATERAL (...) ON TRUEsubquery that can reference columns from precedingFROMitems, enabling O(W·K) index-backed Top-K per group without scanning the full detail table. See Field Note 6. MERGE … RETURNING- PostgreSQL statement that atomically updates matching target rows and inserts non-matching rows from a source table (such as a
pg_tempstaging table), returningmerge_action()(INSERT/UPDATE) plusOLDandNEWvalues in one statement. See Chapter 13. - Prepared-statement shape stability (
= ANY($1)/UNNEST) - Keeping one canonical SQL text regardless of list or batch length so PostgreSQL parses, plans, and caches one prepared statement and produces stable log and
pg_stat_statementsentries (including for bulk inserts, whichIN-list squashing does not cover). See Chapter 3. RETURNING OLD/NEW- Native PostgreSQL clause allowing
UPDATE,DELETE, andMERGEto return both the previous (pg.old(...)) and updated (pg.new(...)) values of a row in a single round trip. See Chapter 2. SKIP LOCKED- Row-locking modifier (
FOR UPDATE SKIP LOCKED) that skips rows currently locked by another transaction instead of blocking, turning an ordinary PostgreSQL table into a concurrent work queue. See Chapter 8. split_load()pgdorm's eager-loading helper that loads parent rows in RTT 1 and pipelines all child relation queries (= ANY($1)) in RTT 2 under a singleREPEATABLE READsnapshot — zero N+1 and zero Cartesian bloat. See Chapter 5.
Wire Protocol, Hydration & Pooling#
- Arrow C Stream (
__arrow_c_stream__) - A standard zero-copy C interface for streaming columnar Apache Arrow
RecordBatches between Python libraries (pgdorm, Polars, DuckDB, PyArrow) without converting rows into Python objects or CSVs. See Chapter 16 and Chapter 17. - Direct Slot Hydration
- Decoding PostgreSQL v3 binary wire cells straight into CPython
tp_alloc+Py_tp_descr_setslot descriptors in a single pass without intermediate RustValuetrees, Python attribute dictionaries, or tuple call frames. See Field Note 5. - ETL / ELT / EtLT
- Three patterns for moving data into a database or warehouse: ETL transforms data before loading (e.g., Polars →
copy_from_arrow()), ELT loads raw data first and transforms inside PostgreSQL SQL (pipe.stage()+pg.merge()), and EtLT runs lightweight pre-load cleanup/typing (on_error="ignore"or Polars) before heavy SQL transforms. See Chapter 13 and Chapter 17. - PgBouncer (
pool_mode=pg.enums.PoolMode.TRANSACTION) - A lightweight PostgreSQL connection pooler that assigns a server connection only for the duration of one transaction. Requires transaction-scoped settings (
set_config(..., true)) andON COMMIT DROPtemp tables. See Chapter 13 and Chapter 14. - Pipeline (
pool.pipeline()/tx.pipeline()) - Sending multiple PostgreSQL extended-query messages (
Parse/Bind/Execute) in one TCP write before a singleSync, completing all statements — including lazyBEGINandCOMMIT— in 1 RTT. See Chapter 10. - Reverse ETL
- Moving curated analytical outputs (audit records, scores, customer segments, pricing tiers) from an analytical engine or lakehouse (DuckDB, Parquet, Polars) back into an operational PostgreSQL OLTP database — done zero-CSV in
pgdormviacopy_from_arrow()(append) orpg_tempstaging +pg.merge()(upsert). See Chapter 17. - RTT (Round Trip Time)
- One full network exchange between your application and PostgreSQL. Counted explicitly in tests with
pool.trace()(assert tr.rtts == 1). See Prologue and Chapter 10. - Server JSON Aggregation (
pool.json(..., mode="server")) - Wrapping a compiled query in PostgreSQL
row_to_json/json_agg(OID114binaryjson) so the database emits a ready-to-forward UTF-8 JSON payload in 1 RTT, minimizing client CPU instructions. See Field Note 5 and Chapter 18.
Migrations & Assimilation#
- Online migration
- Schema evolution broken into lock-friendly steps (
CREATE INDEX CONCURRENTLY,ADD CONSTRAINT ... NOT VALID,VALIDATE CONSTRAINT) guarded bylock_timeout/statement_timeoutso production reads and writes stay unblocked. Provided bypgdorm.migrate. See Chapter 19.
← PreviousTyping & Testingpgdorm.typing Protocols & pgdorm.testing Helpers