I have 2 tables in PostgreSQL
authentication_type
id | name | created_at | updated_at |
---|---|---|---|
c1cc0489-4740-4dca-9d63-14e4c26093ad | password | ... | ... |
accounts
id | password | authentication_type_id | created_at | updated_at | |
---|---|---|---|---|---|
... | [email protected] | (foreign key to the other table) | ... | ... |
I would like to insert the row under the condition that
What I have tried?
CHECK CONSTRAINT (
authentication_type_id='c1cc0489-4740-4dca-9d63-14e4c26093ad'
AND
password IS NOT NULL
)
but this is not working. I am not sure how to write an if else condition here
Questions
I am using sequelize to do this if that helps
You got the boolean logic wrong. You want one (or both) of the following:
CHECK CONSTRAINT (
authentication_type_id != 'c1cc0489-4740-4dca-9d63-14e4c26093ad'
OR
password IS NOT NULL
)