Answer the question
In order to leave comments, you need to log in
How to make a table in postgres with fields that are required depending on the field type?
How to make field1 or field2 in a table in postges one field mandatory and the other field zero when type_id field values are 1 or 2. I.e. if one is filled, the other must not be filled, it must be null.
Here is an example using "limits":
col1 CHECK (((col2 IS NULL) AND (col1 IS NOT NULL)) AND type_id ==2) OR (((col1 IS NULL) AND (col2 IS NOT NULL)) AND type_id == 1)
type_id integer
col2 CHECK (((col1 IS NULL) AND (col2 IS NOT NULL)) AND type_id ==1) OR (((col2 IS NULL) AND (col1 IS NOT NULL)) AND type_id == 2)
Answer the question
In order to leave comments, you need to log in
Can you show the table schema? It seems to me that you have an error in the architecture ... Or I did not quite understand what "types of operations that differ in fields" means
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question