Constraint over two columns in one row

How can I create a constraint over 2 columns in 1 row.?
Say, I have 2 columns file_upload and user_upload, both of which are :boolean type. Now, I want to create a constraint, where user_upload cannot be true if file_upload is false. How to do that? How to write the check condition for the constraint?

Postgres and ecto support check constraints, which allow you to formulate such requirements.

yes, I read those things. But my confusion is, how can I formulate that condition?

I‘ve done it in the past by converting booleans to integer (0 or 1) and enforcing the sum to be less then 2 for your case.

1 Like

Ok, thank you. That helps :slight_smile:

I can do it by converting the boolean to integer, and then use the check condition, file_upload >= user_upload