[MDEV-31769] Adding a check constraint in "create table" doesn't work if it uses a foreign key with "update cascade" Created: 2023-07-24  Updated: 2023-07-25  Resolved: 2023-07-25

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Create Table
Affects Version/s: 10.11.4
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Tim Koop Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None

Issue Links:
Duplicate
duplicates MDEV-31322 FKs with 'ON UPDATE CASCADE' can be s... Closed
Relates
relates to MDEV-12302 Execute triggers for foreign key upda... Confirmed
relates to MDEV-30606 Foreign key cannot be used in the che... Closed

 Description   

This used to work correctly, but at some point it broke.

create table a (
  id int,
  primary key (id)
);
 
-- This works, because update is "restrict"
create table b1 (
  a_id int,
  foreign key (a_id) references a(id) on update restrict,
  check (a_id > 7)
);
 
-- This works, because we are altering the table, even though update is "cascade"
create table b2 (
  a_id int,
  foreign key (a_id) references a(id) on update cascade
);
alter table b2 add check (a_id > 7);
 
-- But "update cascade" doesn't work in the table create
create table b3 (
  a_id int,
  foreign key (a_id) references a(id) on update cascade,
  check (a_id > 7)
);
-- Error in query (1901): Function or expression 'a_id' cannot be used in the CHECK clause of `CONSTRAINT_1`



 Comments   
Comment by Alice Sherepa [ 2023-07-25 ]

Please check the MDEV-30606 comment - about the error, that it was an intentional change.
So the current problem is about ALTER, that it still allows to add the constraint and it is the same issue as MDEV-31322

Generated at Thu Feb 08 10:26:20 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.