clear markdown compare help best fiddles feedback dbanow.uk a leap of faith?
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 936542 fiddles created (12887 in the last week).

create table tableX ( columnA int, CONSTRAINT columnA_UQ UNIQUE (columnA) );
 hidden batch(es)


insert into tableX (columnA) values (1), (2), (null) ;
 hidden batch(es)


insert into tableX (columnA) values (1) ;
Duplicate entry '1' for key 'columnA_UQ'
 hidden batch(es)


ALTER TABLE tableX ADD columnA_single_null int AS (CASE WHEN columnA IS NULL THEN 1 END), ADD CONSTRAINT Single_null_UQ UNIQUE (columnA_single_null) ;
 hidden batch(es)


insert into tableX (columnA) values (1), (2), (null) ;
Duplicate entry '1' for key 'columnA_UQ'
 hidden batch(es)


select columnA from tableX ;
columnA
1
2
 hidden batch(es)


insert into tableX (columnA) values (null) ;
Duplicate entry '1' for key 'Single_null_UQ'
 hidden batch(es)


select columnA from tableX ;
columnA
1
2
 hidden batch(es)