PostgreSQL constraints, triggers and vector search
Most PostgreSQL problems in this pool are not query tuning. They are write-path bugs: a trigger that fires during a cascading delete, an approval that commits before the index job exists, a similarity score that leaves the float32 range and trips a CHECK constraint. Each blueprint names the exact failure, shows the schema or statement that causes it, and gives the smallest change that fixes it — usually one condition in a trigger, one column in a constraint, or one clamp before an INSERT. Everything here was written from a reproducible setup, not from a forum thread, and the entries stay short on purpose: one problem, one cause, one fix.
Triggers and constraints
-
BEFORE DELETE trigger blocks CASCADE
Solution for allowing cascade deletes while blocking direct changes to append-only audit tables in PostgreSQL.
-
PostgreSQL: reject cross-entry revisions
In PostgreSQL, enforce rejection of cross-entry revision approvals and clear only the approval pointer upon revision deletion by referencing the unique pair (entry_id, id) and using a nullable pointer in the delete action.
-
Qdrant score violates a Postgres CHECK
Qdrant's float32 cosine similarity can slightly exceed 1.0, violating Postgres CHECK constraints. Solution: clamp values before insertion.
Migrations and indexing
-
Crash-safe approval in PostgreSQL
To ensure crash-safe approval and indexing in PostgreSQL, store the approval and an open index job in one transaction. Use a worker to claim and process jobs, ensuring atomicity and preventing duplicates.
-
pgvector ivfflat returns zero rows
Explains why ivfflat index may return zero rows on small tables and suggests HNSW as a solution with configuration tips.
Other topics: Home Assistant: entities, automations and device states · Docker Compose: startup, networking and configuration