Last active
May 1, 2020 17:18
-
-
Save victorcrbt/e3576bf240e79c24566fc55627941743 to your computer and use it in GitHub Desktop.
Conditional PostgreSQL not null column.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE clients ( | |
id SERIAL UNIQUE, | |
name varchar(255) NOT NULL, | |
client_type client_type NOT NULL, | |
cpf varchar(11), | |
cnpj varchar(14), | |
CHECK(CASE WHEN client_type = 'F' THEN cpf IS NOT NULL END), | |
CHECK(CASE WHEN client_type = 'J' THEN cnpj IS NOT NULL END) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment