CHECK Constraint Deferrable

Поиск
Список
Период
Сортировка
От Himanshu Upadhyaya
Тема CHECK Constraint Deferrable
Дата
Msg-id CAPF61jBFT6iGv-Af=NrZx3vhqLYqx8WDvfjqVuRVYv2DFbbY4A@mail.gmail.com
обсуждение исходный текст
Ответы Re: CHECK Constraint Deferrable  (Dilip Kumar <dilipbalaut@gmail.com>)
Список pgsql-hackers
Hi,

Currently, there is no support for CHECK constraint DEFERRABLE in a create table statement.
SQL standard specifies that CHECK constraint can be defined as DEFERRABLE.

The attached patch is having implementation for CHECK constraint Deferrable as below:

‘postgres[579453]=#’CREATE TABLE t1 (i int CHECK(i<>0) DEFERRABLE, t text);
CREATE TABLE
‘postgres[579453]=#’\d t1
                 Table "public.t1"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 i      | integer |           |          |
 t      | text    |           |          |
Check constraints:
    "t1_i_check" CHECK (i <> 0) DEFERRABLE

Now we can have a deferrable CHECK constraint, and we can defer the constraint validation:

‘postgres[579453]=#’BEGIN;
BEGIN
‘postgres[579453]=#*’SET CONSTRAINTS t1_i_check DEFERRED;
SET CONSTRAINTS
‘postgres[579453]=#*’INSERT INTO t1 VALUES (0, 'one'); -- should succeed
INSERT 0 1
‘postgres[579453]=#*’UPDATE t1 SET i = 1 WHERE t = 'one';
UPDATE 1
‘postgres[579453]=#*’COMMIT; -- should succeed
COMMIT

Attaching the initial patch, I will improve it with documentation in my next version of the patch.

thoughts?



--
Regards,
Himanshu Upadhyaya
EnterpriseDB: http://www.enterprisedb.com
Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: pg_waldump: add test for coverage
Следующее
От: Heikki Linnakangas
Дата:
Сообщение: Re: Speed up transaction completion faster after many relations are accessed in a transaction