Subject Re: nulls in unique constraints
Author Adam
--- In firebird-support@yahoogroups.com, "Ann W. Harrison"
<aharrison@...> wrote:
>
> Dmitry Yemanov wrote:
> >
> > The behaviour has changed since v1.5.0.
> >
>
> Interesting. I wonder what Adam was testing with that
> he got those odd results.
>

1.5.3 CS (WinXP)

I had read in TFB that such a constraint could not be added to 1.0.x
because each field needed to be a not null field, but it gave no
direction that I could see over how 1.5 would handle it.

I used IBConsole instead of specific 'insert into' to draw my
conclusion. Adding the second record failed, so I used extract
metadata to get the DML to build the table and added the last record.

Given that FB2 behaviour will change, I will change my nulls in C to 0
and leave it as a not null field, even though null does make sense in
this case because it is undefined. Or is it expensive to use a BI trigger?

IF ((NEW.C IS NULL) AND
(EXISTS(SELECT * FROM TABLE WHERE A = NEW.A AND B = NEW.B AND
NEW.C IS NULL)) THEN
BEGIN
EXCEPTION ....
END

There is only a single thread that can insert null in C, so I do not
need to be worried about isolation in this case.

Adam