time of constraint checking
am 20.10.2004 17:58:12 von twanger
Hi,
http://www.postgresql.org/docs/current/static/sql-createtabl e.html says,
down at the explanation of DEFERRABLE, that constraints are checked
after every command. Why does the following not work then:
CREATE TABLE foo (
pos INT UNIQUE
);
INSERT INTO foo (pos) VALUES (1);
INSERT INTO foo (pos) VALUES (2);
UPDATE foo SET pos = CASE WHEN pos = 2 THEN 1 ELSE 2 END;
ERROR: duplicate key violates unique constraint "foo_pos_key"
Also, are deferrable constraints other that FK constraints in the works?
I also noticed, that the docs don't state whether INITIALLY IMMEDIATE or
INITIALLY DEFERRED is the default.
Thanks.
--
Markus Bertheau
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings
Re: time of constraint checking
am 20.10.2004 18:16:04 von twanger
РСÑд, 20.10.2004, в 17:58, Markus Bertheau пиÑеÑ:
> I also noticed, that the docs don't state whether INITIALLY IMMEDIATE or
> INITIALLY DEFERRED is the default.
I just overlooked that, sorry, it is stated.
--
Markus Bertheau
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match
Re: time of constraint checking
am 20.10.2004 18:56:03 von sszabo
On Wed, 20 Oct 2004, Markus Bertheau wrote:
> http://www.postgresql.org/docs/current/static/sql-createtabl e.html says,
> down at the explanation of DEFERRABLE, that constraints are checked
> after every command. Why does the following not work then:
>
> CREATE TABLE foo (
> pos INT UNIQUE
> );
>
> INSERT INTO foo (pos) VALUES (1);
> INSERT INTO foo (pos) VALUES (2);
>
> UPDATE foo SET pos = CASE WHEN pos = 2 THEN 1 ELSE 2 END;
> ERROR: duplicate key violates unique constraint "foo_pos_key"
Unique constraints are currently non-compliant in that it checks on each
changed row rather than at the end of the statement. I thought this was
mentioned somewhere, but it might make sense to mention it in the
compatibility section.
> Also, are deferrable constraints other that FK constraints in the works?
I don't think anyone's looking at it right now.
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster