aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/domains.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils/adt/domains.c')
-rw-r--r--src/backend/utils/adt/domains.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/backend/utils/adt/domains.c b/src/backend/utils/adt/domains.c
index 0aaa9b8be16..5b58ee81a09 100644
--- a/src/backend/utils/adt/domains.c
+++ b/src/backend/utils/adt/domains.c
@@ -25,7 +25,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/domains.c,v 1.8 2009/01/01 17:23:49 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/domains.c,v 1.9 2009/09/09 19:00:09 petere Exp $
*
*-------------------------------------------------------------------------
*/
@@ -302,3 +302,40 @@ domain_recv(PG_FUNCTION_ARGS)
else
PG_RETURN_DATUM(value);
}
+
+/*
+ * domain_check - check that a datum satisfies the constraints of a
+ * domain. extra and mcxt can be passed if they are available from,
+ * say, a FmgrInfo structure, or they can be NULL, in which case the
+ * setup is repeated for each call.
+ */
+void
+domain_check(Datum value, bool isnull, Oid domainType, void **extra, MemoryContext mcxt)
+{
+ DomainIOData *my_extra = NULL;
+
+ if (mcxt == NULL)
+ mcxt = CurrentMemoryContext;
+
+ /*
+ * We arrange to look up the needed info just once per series of calls,
+ * assuming the domain type doesn't change underneath us.
+ */
+ if (extra)
+ my_extra = (DomainIOData *) *extra;
+ if (my_extra == NULL)
+ {
+ my_extra = (DomainIOData *) MemoryContextAlloc(mcxt,
+ sizeof(DomainIOData));
+ domain_state_setup(my_extra, domainType, true, mcxt);
+ if (extra)
+ *extra = (void *) my_extra;
+ }
+ else if (my_extra->domain_type != domainType)
+ domain_state_setup(my_extra, domainType, true, mcxt);
+
+ /*
+ * Do the necessary checks to ensure it's a valid domain value.
+ */
+ domain_check_input(value, isnull, my_extra);
+}