Last active
October 18, 2017 23:11
-
-
Save travisofthenorth/948332daead04c3da947598a9eac0ce7 to your computer and use it in GitHub Desktop.
PG not-null constraint as a check
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
[development] # CREATE TABLE test (id integer, name text); | |
[development] # ALTER TABLE test ADD CHECK (name is not null) NOT VALID; | |
[development] # \d test | |
Table "public.test" | |
Column | Type | Modifiers | |
--------+---------+----------- | |
id | integer | | |
name | text | | |
Check constraints: | |
"test_name_check" CHECK (name IS NOT NULL) NOT VALID | |
[development] # ALTER TABLE test VALIDATE CONSTRAINT "test_name_check"; | |
[development] # INSERT INTO test VALUES (1, NULL); | |
ERROR: 23514: new row for relation "test" violates check constraint "test_name_check" | |
DETAIL: Failing row contains (1, null). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment