aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/prep/preptlist.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/optimizer/prep/preptlist.c')
-rw-r--r--src/backend/optimizer/prep/preptlist.c34
1 files changed, 14 insertions, 20 deletions
diff --git a/src/backend/optimizer/prep/preptlist.c b/src/backend/optimizer/prep/preptlist.c
index 7c439d1947c..c2a77503d4b 100644
--- a/src/backend/optimizer/prep/preptlist.c
+++ b/src/backend/optimizer/prep/preptlist.c
@@ -46,7 +46,8 @@
#include "parser/parsetree.h"
#include "utils/rel.h"
-static List *expand_insert_targetlist(List *tlist, Relation rel);
+static List *expand_insert_targetlist(PlannerInfo *root, List *tlist,
+ Relation rel);
/*
@@ -102,7 +103,7 @@ preprocess_targetlist(PlannerInfo *root)
*/
tlist = parse->targetList;
if (command_type == CMD_INSERT)
- tlist = expand_insert_targetlist(tlist, target_relation);
+ tlist = expand_insert_targetlist(root, tlist, target_relation);
else if (command_type == CMD_UPDATE)
root->update_colnos = extract_update_targetlist_colnos(tlist);
@@ -148,7 +149,8 @@ preprocess_targetlist(PlannerInfo *root)
ListCell *l2;
if (action->commandType == CMD_INSERT)
- action->targetList = expand_insert_targetlist(action->targetList,
+ action->targetList = expand_insert_targetlist(root,
+ action->targetList,
target_relation);
else if (action->commandType == CMD_UPDATE)
action->updateColnos =
@@ -376,7 +378,7 @@ extract_update_targetlist_colnos(List *tlist)
* but now this code is only applied to INSERT targetlists.
*/
static List *
-expand_insert_targetlist(List *tlist, Relation rel)
+expand_insert_targetlist(PlannerInfo *root, List *tlist, Relation rel)
{
List *new_tlist = NIL;
ListCell *tlist_item;
@@ -430,26 +432,18 @@ expand_insert_targetlist(List *tlist, Relation rel)
* confuse code comparing the finished plan to the target
* relation, however.
*/
- Oid atttype = att_tup->atttypid;
- Oid attcollation = att_tup->attcollation;
Node *new_expr;
if (!att_tup->attisdropped)
{
- new_expr = (Node *) makeConst(atttype,
- -1,
- attcollation,
- att_tup->attlen,
- (Datum) 0,
- true, /* isnull */
- att_tup->attbyval);
- new_expr = coerce_to_domain(new_expr,
- InvalidOid, -1,
- atttype,
- 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);
+ /* Must run expression preprocessing on any non-const nodes */
+ if (!IsA(new_expr, Const))
+ new_expr = eval_const_expressions(root, new_expr);
}
else
{