From: | "John Supplee" <john(at)supplee(dot)com> |
---|---|
To: | "'Tom Lane'" <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | <pgsql-bugs(at)postgresql(dot)org> |
Subject: | Re: BUG #2144: Domain NOT NULL constraints ignored in rules |
Date: | 2006-01-05 22:20:48 |
Message-ID: | 20060105222052.A0E6B571482@frontend2.messagingengine.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
Tom Lane wrote:
> Works for me:
>
> regression=# create domain dint as int not null;
> CREATE DOMAIN
> regression=# create table t1 (f1 dint);
> CREATE TABLE
> regression=# create view v1 as select * from t1;
> CREATE VIEW
> regression=# create rule r1 as on insert to v1 do instead
> regression-# insert into t1 values(new.f1);
> CREATE RULE
> regression=# insert into v1 values(1);
> INSERT 0 1
> regression=# insert into v1 values(null);
> ERROR: domain dint does not allow null values
> regression=#
>
> How about a test case?
>
> regards, tom lane
>
>
You need to modify your test case slightly.
test=# create domain dint as int not null;
CREATE DOMAIN
test=# create table t1 (f1 dint, f2 dint);
CREATE TABLE
test=# create view v1 as select * from t1;
CREATE VIEW
test=# create rule r1 as on insert to v1 do instead
test-# insert into t1 values (new.f1, new.f2);
CREATE RULE
test=# insert into v1 values( 1 );
INSERT 0 1
test=# select * from v1;
f1 | f2
----+----
1 |
(1 row)
Notice that f2 has a null value even though the domain constraint should
forbid it.
Now try this:
test=# delete from t1;
DELETE 1
test=# alter table t1 alter column f2 set not null;
ALTER TABLE
test=# insert into v1 values( 1 );
ERROR: null value in column "f2" violates not-null constraint
Having the constraint on the column correctly forbids the NULL value. For
now I have tagged all columns with the NOT NULL constraint individually, but
I think this should be fixed.
John Supplee
From | Date | Subject | |
---|---|---|---|
Next Message | mordicus | 2006-01-06 09:25:53 | Problems building pg 8.1.1 |
Previous Message | Glauco Carlos Silva | 2006-01-05 20:17:00 | BUG #2154: conversion problem |