FIND YOUR NEXT FEW LINES

The snippet library.

Small, practical examples. Search by task or narrow things down below.

10 snippets foundClear filters
PostgresConstraints & defaults

Apply a default when an insert omits a column

Postgres: A default supplies an omitted value; an explicit NULL still follows the column’s nullability rules.

Postgres✓ Tested
PostgresConstraints & defaults

Block deletion of a referenced parent

Postgres: The default foreign-key action prevents deletion while a child still refers to the parent.

Postgres✓ Tested
PostgresConstraints & defaults

Enforce a bounded numeric range

Postgres: A named CHECK constraint keeps numeric values inside an inclusive interval.

Postgres✓ Tested
PostgresConstraints & defaults

Keep children while clearing a deleted relationship

Postgres: ON DELETE SET NULL requires a nullable foreign-key column.

Postgres✓ Tested
PostgresConstraints & defaults

Make a pair of columns unique together

Postgres: A composite primary key permits repeated individual values while forbidding a duplicate combination.

Postgres✓ Tested
PostgresConstraints & defaults

Reference a parent identified by two columns

Postgres: A composite foreign key checks the complete referenced key rather than either column independently.

Postgres✓ Tested
PostgresConstraints & defaults

Reject a negative quantity with CHECK

Postgres: Combine NOT NULL and CHECK because an unknown NULL check result is normally accepted.

Postgres✓ Tested
PostgresConstraints & defaults

Reject duplicate business identifiers

Postgres: A UNIQUE constraint protects a business key independently of the primary key.

Postgres✓ Tested
PostgresConstraints & defaults

Remove dependent rows with a declared cascade

Postgres: ON DELETE CASCADE removes children when their referenced parent is deleted.

Postgres✓ Tested
PostgresConstraints & defaults

Require a value with NOT NULL

Postgres: Declare required fields at the database boundary, not only in application validation.

Postgres✓ Tested