You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A foreign key to a primary key with a prefix length compares only the prefix #2883
A foreign key to a primary key with a prefix length, PRIMARY KEY (a(2)), compares only the prefix, so a value that is not in the parent table is accepted.
vardb=newalasql.Database();db.exec('CREATE TABLE p (a STRING, PRIMARY KEY (a(2))); CREATE TABLE c (x STRING REFERENCES p(a))');db.exec("INSERT INTO p VALUES ('abc')");db.exec("INSERT INTO c VALUES ('abzzz')");// accepted
Expected: the second insert is refused, because no row of p has a = 'abzzz'.
Since #2606 (in 4.21.0; before, the prefix was a parse error). The foreign key check seems to look the value up through the key of the parent, which holds only the prefix. A prefix only decides uniqueness in MySQL; a foreign key compares the whole value.
Activity
mateuscmtropical commentedon Nov 11, 2026
Hi, I'd like to work on this one.
mateuscmtropical commentedon Nov 11, 2026
Hi, I've opened a PR for this: #2985
Fix foreign key for prefixed primary key to close AlaSQL#2883 (AlaSQL…