Subject | Re: [firebird-support] Possible bug with CHECK constraint |
---|---|
Author | Helen Borrie |
Post date | 2004-10-03T00:04:52Z |
At 09:50 PM 2/10/2004 +0000, you wrote:
script and fail next time you insert any *value* at all into id.
Try:
insert into test_master values(3);
ISC ERROR CODE:335544558
Operation violates CHECK constraint INTEG_17 on view or table TEST_MASTER
If you really want this check, try this:
CREATE TABLE test_master1 (
id INTEGER NOT NULL PRIMARY KEY,
CHECK(COALESCE(((SELECT max(id) FROM test_master1) + new.id), 0) < 10)
);
COMMIT;
INSERT INTO test_master1 VALUES (1);
INSERT INTO test_master1 VALUES (20);
COMMIT;
./heLen
>CREATE DATABASE 'test.fdb' USER 'sysdba' PASSWORD 'masterkey';Yes - the check is done before the insert. It should succeed with this
>
>CREATE TABLE test_master (
> id INTEGER NOT NULL PRIMARY KEY,
> CHECK(COALESCE((SELECT max(id) FROM test_master), 0) < 10)
>);
>
>COMMIT;
>
>INSERT INTO test_master VALUES (1);
>INSERT INTO test_master VALUES (20);
>
>COMMIT;
>
>This script succeeds. Is it normal?
script and fail next time you insert any *value* at all into id.
Try:
insert into test_master values(3);
ISC ERROR CODE:335544558
Operation violates CHECK constraint INTEG_17 on view or table TEST_MASTER
If you really want this check, try this:
CREATE TABLE test_master1 (
id INTEGER NOT NULL PRIMARY KEY,
CHECK(COALESCE(((SELECT max(id) FROM test_master1) + new.id), 0) < 10)
);
COMMIT;
INSERT INTO test_master1 VALUES (1);
INSERT INTO test_master1 VALUES (20);
COMMIT;
./heLen