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?
It can be slightly simplified (IF is not needed) and the BOOLEAN could be BIT (not sure if that adds any complication):
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)
);