On 2026-03-11 We 6:34 AM, Viktor Holmberg wrote:
I’ve been burned my this issue in the past so would be great if this could get in.
+/*
+ * DomainHasVolatileConstraints --- check if a domain has constraints with
+ * volatile expressions
+ *
+ * Returns true if the domain has any constraints at all. If have_volatile
+ * is not NULL, also checks whether any CHECK constraint contains a volatile
+ * expression and sets *have_volatile accordingly.
+ *
+ * The caller must initialize *have_volatile before calling (typically to
+ * false). This function only ever sets it to true, never to false.
+ *
+ * This is defined to return false, not fail, if type is not a domain.
+ */
+bool
+DomainHasVolatileConstraints(Oid type_id, bool *have_volatile)
Call it CheckDomainConstraints or something instead? IMO it's confusing
the have it not return what it's called.
Also, it'd make it more self-contained and thus safer to initialise have_volatile to false.
+ if (typentry->domainData != NULL)
+ {
+ if (have_volatile)
+ {
+ foreach_node(DomainConstraintState, constrstate,
+ typentry->domainData->constraints)
+ {
+ if (constrstate->constrainttype == DOM_CONSTRAINT_CHECK &&
+ contain_volatile_functions((Node *) constrstate->check_expr))
+ {
+ *have_volatile = true;
+ break;
+ }
+ }
+ }
+
+ return true;
+ }
+
+ return false;
+}
Could simplify the code by doing an early return if domainData == NULL?
(same with have_volatile below)
I think it's cleaner just to modify the existing function with an extra parameter, which the existing callers will pass as NULL.
Would be nice to test domains with both volatile and non-volatile checks.
Also, perhaps virtual generated columns could use a test?
Also added some tests.
cheers
andrew
--
Andrew Dunstan
EDB: https://www.enterprisedb.com