Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow
INITIALLY IMMEDIATE
constraints
Convert `INITIALLY IMMEDIATE` constraints appearing in `CREATE TABLE` column constraints to `OpCreateTable` operations rather than raw SQL. The documentation is a little misleading, as it makes it sound like `INITIALLY IMMEDIATE` implies that the constraint is `DEFERRABLE`, but in practice it looks like `INITIALLY IMMEDIATE` without `DEFERRABLE` is a no-op. Documentation: https://www.postgresql.org/docs/current/sql-createtable.html#SQL-CREATETABLE-PARMS-INITIALLY In practice: ```sql CREATE TABLE foo(a int PRIMARY KEY GENERATED ALWAYS AS IDENTITY) -- Specify an INITIALLY IMMEDIATE constraint without DEFERRABLE ALTER TABLE foo ADD COLUMN bar int UNIQUE INITIALLY IMMEDIATE -- Query the catalog to see the constraint SELECT conname AS constraint_name, condeferrable AS is_deferrable, condeferred AS is_deferred FROM pg_constraint WHERE conrelid = 'foo'::regclass; ``` Result: ``` +-----------------+---------------+-------------+ | constraint_name | is_deferrable | is_deferred | |-----------------+---------------+-------------| | foo_pkey | False | False | | foo_bar_key | False | False | +-----------------+---------------+-------------+ ``` ie, the `UNIQUE` constraint added to `bar` is not `DEFERRABLE` or `DEFERRED`. In contrast, if the column `bar` is defined: ```sql ALTER TABLE foo ADD COLUMN bar int UNIQUE DEFERRABLE INITIALLY IMMEDIATE ``` Then the same catalog query shows: ``` +-----------------+---------------+-------------+ | constraint_name | is_deferrable | is_deferred | |-----------------+---------------+-------------| | foo_pkey | False | False | | foo_bar_key | True | False | +-----------------+---------------+-------------+ ``` ie, the constraint is `DEFERRABLE`. So specifying `INITIALLY IMMEDIATE` without `DEFERRABLE` is a no-op.
- Loading branch information