PostgreSQL/Constraints/Constraints Basics
Null column
<source lang="sql">
postgres=# CREATE TABLE products ( postgres(# product_no integer NULL, postgres(# name text NULL, postgres(# price numeric NULL postgres(# ); CREATE TABLE postgres=# drop table products; DROP TABLE postgres=# postgres=#
</source>
Specifying range check in table creation
<source lang="sql">
postgres=# postgres=# postgres=# CREATE TABLE products ( postgres(# product_no integer, postgres(# name text, postgres(# price numeric CHECK (price > 0) postgres(# ); CREATE TABLE postgres=# postgres=# postgres=# drop table products; DROP TABLE postgres=#
</source>
Specifying two constaint for a single table
<source lang="sql">
postgres=# postgres=# postgres=# CREATE TABLE products ( postgres(# product_no integer NOT NULL, postgres(# name text NOT NULL, postgres(# price numeric NOT NULL CHECK (price > 0) postgres(# ); CREATE TABLE postgres=# postgres=# drop table products; DROP TABLE postgres=#
</source>