#1117·postgres

Deferred constraint errors not properly detected

Author: arusakovCreated Sep 26, 2025Updated Sep 23, 2026

When working with deferred constraints and performing inserts without an explicit transaction, postgres.js fails to properly detect when an error occurs.

javascript
// table_name contains DEFERRABLE INITIALLY DEFERRED constraint

// insert *value* object with property which breaks the constraint
await sql`INSERT INTO table_name ${sql(value)}`

// no error, no rejected promise

The error is only properly caught when using an explicit transaction with begin() and performing the insert inside the transaction block.

javascript
await sql.begin(async (sql) => {
  await sql`INSERT INTO table_name ${sql(value)}`
})
// rejected promise