Inconsistent foreign key reference into replaced table
Details
| Detail name | Value |
|---|---|
| Changelog Number | 9246 |
| Type | Bug |
| Status | Resolved |
| Affected Versions | Exasol 6.1.0, Exasol 6.2.0 |
| Fix Versions | Exasol 7.0.0, Exasol 6.2.5 |
| Resolution Date | 2020-01-29 |
Background
Exasol does support inline-constraints within a CREATE TABLE statement.
However, all foreign-key references must exist at the time of execution, so self-referencing foreign keys are not supported.
Example
create table TESTTABLE (
id DEC(9) PRIMARY KEY
, parent DEC(9) references TESTTABLE
);
-- [Error 42000] object TESTTABLE not found [line 3, column 32]
Self-referencing foreign keys have to be added separately:
create table TESTTABLE (
id DEC(9) PRIMARY KEY
, parent DEC(9)
);
alter table TESTTABLE add constraint foreign key(parent) references TESTTABLE;
Problem
CREATE OR REPLACE of an existing table manages to fool that object check but results in an invalid internal state for the table's metadata, breaking some operations.
Example:
create table TESTTABLE (
id DEC(9) PRIMARY KEY
, parent DEC(9)
);
create OR REPLACE table TESTTABLE (
id DEC(9) PRIMARY KEY
, parent DEC(9) references TESTTABLE
);
select * from SYS.EXA_ALL_CONSTRAINT_COLUMNS;
-- [Error 42000] Trying to access already dropped object with id 6679552!
insert into TESTTABLE values (1,null);
-- ok
insert into TESTTABLE values (2,1);
-- [Error 27003] constraint violation - foreign key (SYS_13232026751655984109318144 on table TESTTABLE)