Skip to content

Composite foreign key with NULL in some columns: MATCH SIMPLE as SQLite #2663

Open

Description

@mathiasrw

A composite foreign key with NULL in some, but not all, of its columns is rejected. SQL's default rule (MATCH SIMPLE), and SQLite, skip the check as soon as any column is NULL.

Reproduced on develop, compared with SQLite 3.43 (PRAGMA foreign_keys=ON):

CREATE TABLE p (a INT, b INT, PRIMARY KEY (a, b));
INSERT INTO p VALUES (1, 1);
CREATE TABLE c (x INT, y INT, FOREIGN KEY (x, y) REFERENCES p (a, b));
INSERT INTO c VALUES (1, NULL);
-- AlaSQL: Invalid foreign key on table undefined
-- SQLite: inserted

The message also names the table undefined: it reads table.tableid, and the table object has no tableid. The same applies to the error at CREATE TABLE when a foreign key names more referenced columns than its own.

Direction

Skip the check when any column of the foreign key is NULL. Use the table's name in both messages.

This turns a wrong error into the right result, so it can go into 4.x.

Related: #1179, #2662.

Activity

  1. added this to the Breaking change milestone on Oct 20, 2026
  2. changed the title [-]Composite foreign key with NULL in some columns is rejected, and the error names the table undefined[/-] [+]Composite foreign key with NULL in some columns: MATCH SIMPLE as SQLite (5.0)[/+] on Oct 20, 2026
  3. mathiasrw commented on Oct 20, 2026

    @mathiasrw
    MemberAuthor

    Decided 2026-10-20: the error message part (table name instead of undefined) goes into 4.x with #2664. Accepting NULL in some columns (MATCH SIMPLE) is a breaking change: today partial keys are refused on purpose (test807), and people can rely on that. It goes to 5.0. Way back: a CHECK that refuses a partial key.

  4. changed the title [-]Composite foreign key with NULL in some columns: MATCH SIMPLE as SQLite (5.0)[/-] [+]Composite foreign key with NULL in some columns: MATCH SIMPLE as SQLite[/+] on Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions