~ubuntu-branches/ubuntu/trusty/postgresql-8.4/trusty

« back to all changes in this revision

Viewing changes to src/backend/parser/parse_expr.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-11 16:59:35 UTC
  • mfrom: (5.1.1 karmic)
  • Revision ID: james.westby@ubuntu.com-20090711165935-jfwin6gfrxf0gfsi
Tags: 8.4.0-2
* debian/libpq-dev.install: Ship catalog/genbki.h. (Closes: #536139)
* debian/rules: Drop --enable-cassert for final release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 *
9
9
 *
10
10
 * IDENTIFICATION
11
 
 *        $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.240 2009/01/22 20:16:05 tgl Exp $
 
11
 *        $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.241 2009/06/11 14:49:00 momjian Exp $
12
12
 *
13
13
 *-------------------------------------------------------------------------
14
14
 */
147
147
                                TypeCast   *tc = (TypeCast *) expr;
148
148
 
149
149
                                /*
150
 
                                 * If the subject of the typecast is an ARRAY[] construct
151
 
                                 * and the target type is an array type, we invoke
152
 
                                 * transformArrayExpr() directly so that we can pass down
153
 
                                 * the type information.  This avoids some cases where
 
150
                                 * If the subject of the typecast is an ARRAY[] construct and
 
151
                                 * the target type is an array type, we invoke
 
152
                                 * transformArrayExpr() directly so that we can pass down the
 
153
                                 * type information.  This avoids some cases where
154
154
                                 * transformArrayExpr() might not infer the correct type.
155
155
                                 */
156
156
                                if (IsA(tc->arg, A_ArrayExpr))
173
173
                                        }
174
174
 
175
175
                                        /*
176
 
                                         * Corner case: ARRAY[] cast to a non-array type.
177
 
                                         * Fall through to do it the standard way.
 
176
                                         * Corner case: ARRAY[] cast to a non-array type. Fall
 
177
                                         * through to do it the standard way.
178
178
                                         */
179
179
                                }
180
180
 
961
961
         * We try to generate a ScalarArrayOpExpr from IN/NOT IN, but this is only
962
962
         * possible if the inputs are all scalars (no RowExprs) and there is a
963
963
         * suitable array type available.  If not, we fall back to a boolean
964
 
         * condition tree with multiple copies of the lefthand expression.
965
 
         * Also, any IN-list items that contain Vars are handled as separate
966
 
         * boolean conditions, because that gives the planner more scope for
967
 
         * optimization on such clauses.
 
964
         * condition tree with multiple copies of the lefthand expression. Also,
 
965
         * any IN-list items that contain Vars are handled as separate boolean
 
966
         * conditions, because that gives the planner more scope for optimization
 
967
         * on such clauses.
968
968
         *
969
969
         * First step: transform all the inputs, and detect whether any are
970
970
         * RowExprs or contain Vars.
985
985
        }
986
986
 
987
987
        /*
988
 
         * ScalarArrayOpExpr is only going to be useful if there's more than
989
 
         * one non-Var righthand item.  Also, it won't work for RowExprs.
 
988
         * ScalarArrayOpExpr is only going to be useful if there's more than one
 
989
         * non-Var righthand item.      Also, it won't work for RowExprs.
990
990
         */
991
991
        if (!haveRowExpr && list_length(rnonvars) > 1)
992
992
        {
995
995
                Oid                     array_type;
996
996
 
997
997
                /*
998
 
                 * Try to select a common type for the array elements.  Note that
 
998
                 * Try to select a common type for the array elements.  Note that
999
999
                 * since the LHS' type is first in the list, it will be preferred when
1000
1000
                 * there is doubt (eg, when all the RHS items are unknown literals).
1001
1001
                 *
1266
1266
                                (errcode(ERRCODE_SYNTAX_ERROR),
1267
1267
                                 errmsg("subquery cannot have SELECT INTO"),
1268
1268
                                 parser_errposition(pstate,
1269
 
                                                                        exprLocation((Node *) qtree->intoClause))));
 
1269
                                                                 exprLocation((Node *) qtree->intoClause))));
1270
1270
 
1271
1271
        sublink->subselect = (Node *) qtree;
1272
1272
 
1398
1398
        Oid                     coerce_type;
1399
1399
        bool            coerce_hard;
1400
1400
 
1401
 
        /* 
1402
 
         * Transform the element expressions 
 
1401
        /*
 
1402
         * Transform the element expressions
1403
1403
         *
1404
 
         * Assume that the array is one-dimensional unless we find an
1405
 
         * array-type element expression.
1406
 
         */ 
 
1404
         * Assume that the array is one-dimensional unless we find an array-type
 
1405
         * element expression.
 
1406
         */
1407
1407
        newa->multidims = false;
1408
1408
        foreach(element, a->elements)
1409
1409
        {
1411
1411
                Node       *newe;
1412
1412
 
1413
1413
                /*
1414
 
                 * If an element is itself an A_ArrayExpr, recurse directly so that
1415
 
                 * we can pass down any target type we were given.
 
1414
                 * If an element is itself an A_ArrayExpr, recurse directly so that we
 
1415
                 * can pass down any target type we were given.
1416
1416
                 */
1417
1417
                if (IsA(e, A_ArrayExpr))
1418
1418
                {
1428
1428
                else
1429
1429
                {
1430
1430
                        newe = transformExpr(pstate, e);
 
1431
 
1431
1432
                        /*
1432
 
                         * Check for sub-array expressions, if we haven't already
1433
 
                         * found one.
 
1433
                         * Check for sub-array expressions, if we haven't already found
 
1434
                         * one.
1434
1435
                         */
1435
1436
                        if (!newa->multidims && type_is_array(exprType(newe)))
1436
1437
                                newa->multidims = true;
1439
1440
                newelems = lappend(newelems, newe);
1440
1441
        }
1441
1442
 
1442
 
        /* 
 
1443
        /*
1443
1444
         * Select a target type for the elements.
1444
1445
         *
1445
1446
         * If we haven't been given a target array type, we must try to deduce a
1473
1474
                        if (!OidIsValid(element_type))
1474
1475
                                ereport(ERROR,
1475
1476
                                                (errcode(ERRCODE_UNDEFINED_OBJECT),
1476
 
                                                 errmsg("could not find element type for data type %s",
1477
 
                                                                format_type_be(array_type)),
 
1477
                                           errmsg("could not find element type for data type %s",
 
1478
                                                          format_type_be(array_type)),
1478
1479
                                                 parser_errposition(pstate, a->location)));
1479
1480
                }
1480
1481
                else
1492
1493
        }
1493
1494
 
1494
1495
        /*
1495
 
         * Coerce elements to target type 
 
1496
         * Coerce elements to target type
1496
1497
         *
1497
1498
         * If the array has been explicitly cast, then the elements are in turn
1498
1499
         * explicitly coerced.
1500
1501
         * If the array's type was merely derived from the common type of its
1501
1502
         * elements, then the elements are implicitly coerced to the common type.
1502
1503
         * This is consistent with other uses of select_common_type().
1503
 
         */ 
 
1504
         */
1504
1505
        foreach(element, newelems)
1505
1506
        {
1506
1507
                Node       *e = (Node *) lfirst(element);
1508
1509
 
1509
1510
                if (coerce_hard)
1510
1511
                {
1511
 
                        newe = coerce_to_target_type(pstate, e, 
 
1512
                        newe = coerce_to_target_type(pstate, e,
1512
1513
                                                                                 exprType(e),
1513
 
                                                                                 coerce_type, 
 
1514
                                                                                 coerce_type,
1514
1515
                                                                                 typmod,
1515
1516
                                                                                 COERCION_EXPLICIT,
1516
1517
                                                                                 COERCE_EXPLICIT_CAST,
1671
1672
                        ereport(ERROR,
1672
1673
                                        (errcode(ERRCODE_SYNTAX_ERROR),
1673
1674
                                         x->op == IS_XMLELEMENT
1674
 
                                         ? errmsg("unnamed XML attribute value must be a column reference")
1675
 
                                         : errmsg("unnamed XML element value must be a column reference"),
 
1675
                        ? errmsg("unnamed XML attribute value must be a column reference")
 
1676
                        : errmsg("unnamed XML element value must be a column reference"),
1676
1677
                                         parser_errposition(pstate, r->location)));
1677
1678
                        argname = NULL;         /* keep compiler quiet */
1678
1679
                }
1687
1688
                                if (strcmp(argname, strVal(lfirst(lc2))) == 0)
1688
1689
                                        ereport(ERROR,
1689
1690
                                                        (errcode(ERRCODE_SYNTAX_ERROR),
1690
 
                                                         errmsg("XML attribute name \"%s\" appears more than once",
1691
 
                                                                        argname),
 
1691
                                        errmsg("XML attribute name \"%s\" appears more than once",
 
1692
                                                   argname),
1692
1693
                                                         parser_errposition(pstate, r->location)));
1693
1694
                        }
1694
1695
                }