How to create unique constraint on NULL columns - Mailing list pgsql-general

I have table

CREATE TABLE test( col1 CHAR NOT NULL, col2 CHAR,
  UNIQUE (col1, col2) );

This table allows to insert duplicate rows if col2 is NULL:

INSERT INTO test VALUES ( '1', NULL );
INSERT INTO test VALUES ( '1', NULL );

does NOT cause error!

How to create constraint so that NULL values are treated equal and second
insert is rejected ?

Andrus.



pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Function returning any (tuple) type
Next
From: Kevin Murphy
Date:
Subject: Re: What's Popular for CMS and RAD with PHP/PostgreSQL?