Didn't CHECK CONSTRAINTS get introduced in MySQL 8? Then better port it from there into MariaDB I think. -- Peter
On Sun, Oct 16, 2016 at 4:45 PM, Pantelis Theodosiou <ypercube@gmail.com> wrote:It can be slightly simplified (IF is not needed) and the BOOLEAN could be BIT (not sure if that adds any complication):Would this be good to be added in the documentation of VIRTUAL columns?Or as a separate page, as a way to enforce/emulate arbitrary CHECK constraints?CREATE TABLE truth (t BIT PRIMARY KEY) ;INSERT INTO truth (t) VALUES (TRUE) ;-- and remove all write permissions to the table
CREATE TABLE checker (
i float,
i_must_be_between_7_and_12 BIT
AS (i BETWEEN 7 AND 12) -- whatever CHECK constraint we want here
PERSISTENT,CONSTRAINT check_i_must_be_between_7_and_12 FOREIGN KEY (i_must_be_between_7_and_12)REFERENCES truth (t));