I would like to know if it's possible to create table with a not null constraint on a column depending of the value of another column in another table. (In postgres)
exemple:
CREATE TABLE IF NOT EXISTS Ref (
id SERIAL PRIMARY KEY,
required BOOLEAN DEFAULT FALSE
);
CREATE TABLE IF NOT EXISTS Value (
id SERIAL PRIMARY KEY,
refId INTEGER REFERENCES Ref(id) NOT NULL,
value TEXT,
);
So here I would like to add a constraint NOT NULL to value if required is TRUE.
So I tried to use some check but it seem that it only check column inside the same table :(.
Thanks in advance.
requiredcolumn to theValuetable, or (b) duplicate it in both tables and then automatically duplicate the values bytrigger functions, or byrule, or (c) implement the constraint intrigger functionsapplying to tableValuewhile testing therequiredcolumn in tableRef