diff options
Diffstat (limited to 'src/backend/rewrite')
-rw-r--r-- | src/backend/rewrite/rewriteHandler.c | 42 | ||||
-rw-r--r-- | src/backend/rewrite/rewriteManip.c | 30 |
2 files changed, 26 insertions, 46 deletions
diff --git a/src/backend/rewrite/rewriteHandler.c b/src/backend/rewrite/rewriteHandler.c index b74f2acc327..847edcfa90e 100644 --- a/src/backend/rewrite/rewriteHandler.c +++ b/src/backend/rewrite/rewriteHandler.c @@ -1008,23 +1008,11 @@ rewriteTargetListIU(List *targetList, if (commandType == CMD_INSERT) new_tle = NULL; else - { - new_expr = (Node *) makeConst(att_tup->atttypid, - -1, - att_tup->attcollation, - att_tup->attlen, - (Datum) 0, - true, /* isnull */ - att_tup->attbyval); - /* this is to catch a NOT NULL domain constraint */ - new_expr = coerce_to_domain(new_expr, - InvalidOid, -1, - att_tup->atttypid, - COERCION_IMPLICIT, - COERCE_IMPLICIT_CAST, - -1, - false); - } + new_expr = coerce_null_to_domain(att_tup->atttypid, + att_tup->atttypmod, + att_tup->attcollation, + att_tup->attlen, + att_tup->attbyval); } if (new_expr) @@ -1572,21 +1560,11 @@ rewriteValuesRTE(Query *parsetree, RangeTblEntry *rte, int rti, continue; } - new_expr = (Node *) makeConst(att_tup->atttypid, - -1, - att_tup->attcollation, - att_tup->attlen, - (Datum) 0, - true, /* isnull */ - att_tup->attbyval); - /* this is to catch a NOT NULL domain constraint */ - new_expr = coerce_to_domain(new_expr, - InvalidOid, -1, - att_tup->atttypid, - COERCION_IMPLICIT, - COERCE_IMPLICIT_CAST, - -1, - false); + new_expr = coerce_null_to_domain(att_tup->atttypid, + att_tup->atttypmod, + att_tup->attcollation, + att_tup->attlen, + att_tup->attbyval); } newList = lappend(newList, new_expr); } diff --git a/src/backend/rewrite/rewriteManip.c b/src/backend/rewrite/rewriteManip.c index bca11500e9e..a115b217c91 100644 --- a/src/backend/rewrite/rewriteManip.c +++ b/src/backend/rewrite/rewriteManip.c @@ -22,6 +22,7 @@ #include "parser/parse_relation.h" #include "parser/parsetree.h" #include "rewrite/rewriteManip.h" +#include "utils/lsyscache.h" typedef struct @@ -1802,20 +1803,21 @@ ReplaceVarsFromTargetList_callback(Var *var, return (Node *) var; case REPLACEVARS_SUBSTITUTE_NULL: - - /* - * If Var is of domain type, we should add a CoerceToDomain - * node, in case there is a NOT NULL domain constraint. - */ - return coerce_to_domain((Node *) makeNullConst(var->vartype, - var->vartypmod, - var->varcollid), - InvalidOid, -1, - var->vartype, - COERCION_IMPLICIT, - COERCE_IMPLICIT_CAST, - -1, - false); + { + /* + * If Var is of domain type, we must add a CoerceToDomain + * node, in case there is a NOT NULL domain constraint. + */ + int16 vartyplen; + bool vartypbyval; + + get_typlenbyval(var->vartype, &vartyplen, &vartypbyval); + return coerce_null_to_domain(var->vartype, + var->vartypmod, + var->varcollid, + vartyplen, + vartypbyval); + } } elog(ERROR, "could not find replacement targetlist entry for attno %d", var->varattno); |