aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_expr.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-12-23 14:07:24 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2012-12-23 14:07:24 -0500
commit31bc839724439440b2e94ea616b28ce5be94e19c (patch)
tree1bd0a7137b12f16840be1f361eb2678415ad297e /src/backend/parser/parse_expr.c
parenteb035068121532ed7db47081e71655746d31cd16 (diff)
downloadpostgresql-31bc839724439440b2e94ea616b28ce5be94e19c.tar.gz
postgresql-31bc839724439440b2e94ea616b28ce5be94e19c.zip
Prevent failure when RowExpr or XmlExpr is parse-analyzed twice.
transformExpr() is required to cope with already-transformed expression trees, for various ugly-but-not-quite-worth-cleaning-up reasons. However, some of its newer subroutines hadn't gotten the memo. This accounts for bug #7763 from Norbert Buchmuller: transformRowExpr() was overwriting the previously determined type of a RowExpr during CREATE TABLE LIKE INCLUDING INDEXES. Additional investigation showed that transformXmlExpr had the same kind of problem, but all the other cases seem to be safe. Andres Freund and Tom Lane
Diffstat (limited to 'src/backend/parser/parse_expr.c')
-rw-r--r--src/backend/parser/parse_expr.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index e9267c56fc5..3b1b6d0139c 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -92,6 +92,8 @@ static Expr *make_distinct_op(ParseState *pstate, List *opname,
* function argument to the required type (via coerce_type())
* can apply transformExpr to an already-transformed subexpression.
* An example here is "SELECT count(*) + 1.0 FROM table".
+ * 3. CREATE TABLE t1 (LIKE t2 INCLUDING INDEXES) can pass in
+ * already-transformed index expressions.
* While it might be possible to eliminate these cases, the path of
* least resistance so far has been to ensure that transformExpr() does
* no damage if applied to an already-transformed tree. This is pretty
@@ -1775,11 +1777,17 @@ transformArrayExpr(ParseState *pstate, A_ArrayExpr *a,
static Node *
transformRowExpr(ParseState *pstate, RowExpr *r)
{
- RowExpr *newr = makeNode(RowExpr);
+ RowExpr *newr;
char fname[16];
int fnum;
ListCell *lc;
+ /* If we already transformed this node, do nothing */
+ if (OidIsValid(r->row_typeid))
+ return (Node *) r;
+
+ newr = makeNode(RowExpr);
+
/* Transform the field expressions */
newr->args = transformExpressionList(pstate, r->args, pstate->p_expr_kind);
@@ -1880,16 +1888,23 @@ transformMinMaxExpr(ParseState *pstate, MinMaxExpr *m)
static Node *
transformXmlExpr(ParseState *pstate, XmlExpr *x)
{
- XmlExpr *newx = makeNode(XmlExpr);
+ XmlExpr *newx;
ListCell *lc;
int i;
+ /* If we already transformed this node, do nothing */
+ if (OidIsValid(x->type))
+ return (Node *) x;
+
+ newx = makeNode(XmlExpr);
newx->op = x->op;
if (x->name)
newx->name = map_sql_identifier_to_xml_name(x->name, false, false);
else
newx->name = NULL;
newx->xmloption = x->xmloption;
+ newx->type = XMLOID; /* this just marks the node as transformed */
+ newx->typmod = -1;
newx->location = x->location;
/*