Fix failure to apply domain constraints to a NULL constant that's added to
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 6 Jan 2006 20:11:18 +0000 (20:11 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 6 Jan 2006 20:11:18 +0000 (20:11 +0000)
an INSERT target list during rule rewriting.  Per report from John Supplee.

src/backend/rewrite/rewriteManip.c

index 8f5081359fbac431c57f21beab9d8532f306280a..acba5f9f4fd595ebf80d0a7c707729a584975f57 100644 (file)
@@ -18,6 +18,7 @@
 #include "optimizer/clauses.h"
 #include "optimizer/tlist.h"
 #include "parser/parsetree.h"
+#include "parser/parse_coerce.h"
 #include "parser/parse_relation.h"
 #include "rewrite/rewriteManip.h"
 #include "utils/lsyscache.h"
@@ -838,7 +839,13 @@ resolve_one_var(Var *var, ResolveNew_context *context)
                else
                {
                        /* Otherwise replace unmatched var with a null */
-                       return (Node *) makeNullConst(var->vartype);
+                       /* need coerce_to_domain in case of NOT NULL domain constraint */
+                       return coerce_to_domain((Node *) makeNullConst(var->vartype),
+                                                                       InvalidOid,
+                                                                       var->vartype,
+                                                                       COERCE_IMPLICIT_CAST,
+                                                                       false,
+                                                                       false);
                }
        }
        else