Re: BUG #2144: Domain NOT NULL constraints ignored in rules - Mailing list pgsql-bugs

From John Supplee
Subject Re: BUG #2144: Domain NOT NULL constraints ignored in rules
Date
Msg-id 20060105222052.A0E6B571482@frontend2.messagingengine.com
Whole thread Raw
In response to Re: BUG #2144: Domain NOT NULL constraints ignored in rules  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: BUG #2144: Domain NOT NULL constraints ignored in rules
List 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

pgsql-bugs by date:

Previous
From: "Norman Young"
Date:
Subject: BUG #2153: atan2(0, 0) ERROR: input is out of range on Solaris
Next
From: "Glauco Carlos Silva"
Date:
Subject: BUG #2154: conversion problem