Querious Help 5

Constraints & Sequences

PostgreSQL check constraints, unique constraints, and column sequences.

On PostgreSQL, the table Structure view has a Constraints & Sequences subview with three lists: check constraints, unique constraints, and the sequences behind the table's auto-numbered columns.

Unlike the Columns subview, changes here run as soon as you make them. There's no Apply step. If the server rejects a change, the error is shown and the table is left as it was.

Check Constraints #

Use a check constraint to have the server reject rows that break a rule, such as price >= 0 or ends_at > starts_at.

Column What it is
Name Optional. Leave it empty to let the server name the constraint.
Expression The condition every row must satisfy, without the CHECK keyword or parentheses.
  • Click to add a constraint. Querious fills in a placeholder expression to replace, and adds the constraint when you select another row.
  • Double-click a name or expression to edit it. Renaming uses RENAME CONSTRAINT. Changing the expression drops the constraint and adds it again.
  • Click to drop the selected constraint.

Unique Constraints #

Use a unique constraint to require that no two rows share the same values in a set of columns, such as one account per email address.

Column What it is
Name Optional. Leave it empty to let the server name the constraint.
Columns The columns that must be unique together. Double-click to choose them in a popover.
Nulls Distinct On (the default), rows with NULL in these columns never conflict with each other. Off (NULLS NOT DISTINCT) treats NULLs as equal, so only one such row is allowed. Turning it off requires PostgreSQL 15 or later.
Deferrable Whether the check can be put off until the end of a transaction.
Deferred Whether it is put off by default (INITIALLY DEFERRED). Turning this on also turns on Deferrable.

Changing anything but the name drops the constraint and adds it again.

Primary keys are unique too, but are edited in Indexes and Keys.

Sequences #

Lists the sequence behind each column that gets its values from one, such as serial and identity columns.

Column What it is
Column The column that uses the sequence.
Sequence The sequence's name. Editable, to rename it.
Type The sequence's data type, such as integer or bigint.
Min, Max The lowest and highest values it can produce.
Starting The value it starts at, and returns to when restarted.
Increment How much each new value goes up by.

Double-click a value to change it. Each change runs ALTER SEQUENCE immediately.