Applies to: every SQL backend; the thread converted TPS to PostgreSQL.
Problem
A key marked Unique and "Exclude Empty Keys" worked on TPS: records with an empty value were simply not in the key. On PostgreSQL the second record with JobNumber = 0 fails with a unique violation.
Solution
"Exclude Empty Keys" is a TPS feature. A SQL unique index ignores NULL, not zero or blank: Clarion sends 0, the server sees a real value, and the second 0 collides. Store NULL for "empty": SETNULL() on the column before the insert (and SETNONNULL / NULL() when reading), so the server excludes those rows the way TPS did.
Caveats
- SQL Server allows only one NULL in a unique index (older versions and the default behaviour). From SQL Server 2008 use a filtered unique index:
CREATE UNIQUE INDEX ix ON T(col) WHERE col IS NOT NULL. PostgreSQL and Oracle accept several NULLs, as the ANSI standard says. - If the column should be a server-assigned number, use the server's auto-increment instead of a unique value the user types; see the auto-increment entry.
Today (2026)
Unchanged.
Sources: Alexander (Nov 2015, the question), John S., Jon W., Arnor B. (Nov 2015) in softvelocity.clarion.databasedrivers.