Skip to content

Instantly share code, notes, and snippets.

@knmkr
Created March 16, 2015 07:01
Show Gist options
  • Save knmkr/f861d92bb6369016902c to your computer and use it in GitHub Desktop.
Save knmkr/f861d92bb6369016902c to your computer and use it in GitHub Desktop.
Not null check in combination: check (foo is not null) or (bar is not null).
DROP TABLE IF EXISTS snp_info;
CREATE TABLE snp_info (
snp_id varchar NOT NULL,
foo integer,
bar integer
CHECK (foo IS NOT NULL OR bar IS NOT NULL)
);
-- Success:
-- INSERT INTO snp_info VALUES ('rs10', 1, NULL);
-- INSERT INTO snp_info VALUES ('rs10', NULL, 1);
-- Fail:
-- INSERT INTO snp_info VALUES ('rs10', NULL, NULL);
-- INSERT INTO snp_info VALUES (NULL, NULL, NULL);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment