From f6162912c0fb4f5a08108accd53fd9368e580e59 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc kop@karlpinc.com" Date: Thu, 28 May 2026 17:43:02 +0000 Subject: [PATCH] New null_xor_null() macro: exactly one of 2 columns must be NULL --- db/include/tablemacros.m4 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/db/include/tablemacros.m4 b/db/include/tablemacros.m4 index d623edf..8452b9e 100644 --- a/db/include/tablemacros.m4 +++ b/db/include/tablemacros.m4 @@ -264,6 +264,21 @@ define([null_iff_null], [ CONSTRAINT "$1 must be NULL if and only if OR ($1 IS NOT NULL AND $2 IS NOT NULL))])dnl changequote(`,')dnl See above +-- One member of a pair of columns must NULL and the other non-NULL. +-- +-- Syntax: null_xor_null(col1, col2) +-- +-- Input: +-- col1 Name of one of the columns. +-- col2 Name of the other column. +-- +changequote([,]) +define([null_xor_null], [CONSTRAINT "One of $1 and $2 must be NULL and the other not-NULL" + CHECK(($1 IS NULL + OR $2 IS NULL) + AND COALESCE($1, $2) IS NOT NULL)])dnl +changequote(`,')dnl See above + -- One column must be NULL if another is. -- -- Syntax: null_if_null(col1, col2) -- 2.34.1