CREATE TABLE a (
    id UUID NOT NULL DEFAULT gen_random_uuid(),
    PRIMARY KEY (id)
);

CREATE TABLE aa (
    a UUID NOT NULL,
    at TIMESTAMPTZ NOT NULL DEFAULT statement_timestamp(),
    PRIMARY KEY (a, at),
    CONSTRAINT fk_a FOREIGN KEY (a) REFERENCES a (id)
) INTERLEAVE IN PARENT a (a);

CREATE TABLE ab (
    a UUID NOT NULL,
    at TIMESTAMPTZ NOT NULL DEFAULT statement_timestamp(),
    PRIMARY KEY (a, at),
    CONSTRAINT fk_a FOREIGN KEY (a) REFERENCES a (id)
) INTERLEAVE IN PARENT a (a);

CREATE TABLE ac (
    a UUID NOT NULL,
    a1 UUID NOT NULL CHECK (a = a1),                            -- <====== duplicate 'a' here with a check() statement
    aa TIMESTAMPTZ,
    ab TIMESTAMPTZ,
    PRIMARY KEY (a),
    CONSTRAINT fk_a FOREIGN KEY (a) REFERENCES a (id),
    CONSTRAINT fk_aa FOREIGN KEY (a, aa) REFERENCES aa (a, at),
    CONSTRAINT fk_ab FOREIGN KEY (a1, ab) REFERENCES ab (a, at) -- <====== use the duplicate 'a1' instead in the FK constraint
) INTERLEAVE IN PARENT a (a);
