diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2000-10-07 00:58:23 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2000-10-07 00:58:23 +0000 |
commit | fbd26d69846fcbfb69deee45bdddcc692dd59b07 (patch) | |
tree | 2aee8f89268d64645b1c4c96958a0e575a12e259 /src/backend/parser/parse_expr.c | |
parent | 4837270be9cbba925a7003de5980918c3de8fb37 (diff) | |
download | postgresql-fbd26d69846fcbfb69deee45bdddcc692dd59b07.tar.gz postgresql-fbd26d69846fcbfb69deee45bdddcc692dd59b07.zip |
Arrange that no database accesses are attempted during parser() --- this
took some rejiggering of typename and ACL parsing, as well as moving
parse_analyze call out of parser(). Restructure postgres.c processing
so that parse analysis and rewrite are skipped when in abort-transaction
state. Only COMMIT and ABORT statements will be processed beyond the raw
parser() phase. This addresses problem of parser failing with database access
errors while in aborted state (see pghackers discussions around 7/28/00).
Also fix some bugs with COMMIT/ABORT statements appearing in the middle of
a single query input string.
Function, operator, and aggregate arguments/results can now use full
TypeName production, in particular foo[] for array types.
DROP OPERATOR and COMMENT ON OPERATOR were broken for unary operators.
Allow CREATE AGGREGATE to accept unquoted numeric constants for initcond.
Diffstat (limited to 'src/backend/parser/parse_expr.c')
-rw-r--r-- | src/backend/parser/parse_expr.c | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c index 7b647124d1f..94ccaa5f69f 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.85 2000/10/05 19:11:33 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.86 2000/10/07 00:58:17 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -294,8 +294,7 @@ transformExpr(ParseState *pstate, Node *expr, int precedence) break; } pstate->p_hasSubLinks = true; - qtrees = parse_analyze(makeList1(sublink->subselect), - pstate); + qtrees = parse_analyze(sublink->subselect, pstate); if (length(qtrees) != 1) elog(ERROR, "Bad query in subselect"); qtree = (Query *) lfirst(qtrees); @@ -821,19 +820,21 @@ exprIsLengthCoercion(Node *expr, int32 *coercedTypmod) static Node * parser_typecast_constant(Value *expr, TypeName *typename) { - Const *con; Type tp; Datum datum; + Const *con; char *const_string = NULL; bool string_palloced = false; bool isNull = false; + tp = typenameType(TypeNameToInternalName(typename)); + switch (nodeTag(expr)) { case T_Integer: - string_palloced = true; const_string = DatumGetCString(DirectFunctionCall1(int4out, Int32GetDatum(expr->val.ival))); + string_palloced = true; break; case T_Float: case T_String: @@ -844,19 +845,9 @@ parser_typecast_constant(Value *expr, TypeName *typename) break; default: elog(ERROR, "Cannot cast this expression to type '%s'", - typename->name); + typeTypeName(tp)); } - if (typename->arrayBounds != NIL) - { - char type_string[NAMEDATALEN + 2]; - - sprintf(type_string, "_%s", typename->name); - tp = (Type) typenameType(type_string); - } - else - tp = (Type) typenameType(typename->name); - if (isNull) datum = (Datum) NULL; else @@ -892,15 +883,7 @@ parser_typecast_expression(ParseState *pstate, Type tp; Oid targetType; - if (typename->arrayBounds != NIL) - { - char type_string[NAMEDATALEN + 2]; - - sprintf(type_string, "_%s", typename->name); - tp = (Type) typenameType(type_string); - } - else - tp = (Type) typenameType(typename->name); + tp = typenameType(TypeNameToInternalName(typename)); targetType = typeTypeId(tp); if (inputType == InvalidOid) @@ -925,3 +908,26 @@ parser_typecast_expression(ParseState *pstate, return expr; } + +/* + * Given a TypeName node as returned by the grammar, generate the internal + * name of the corresponding type. Note this does NOT check if the type + * exists or not. + */ +char * +TypeNameToInternalName(TypeName *typename) +{ + if (typename->arrayBounds != NIL) + { + /* + * By convention, the name of an array type is the name of its + * element type with "_" prepended. + */ + char *arrayname = palloc(strlen(typename->name) + 2); + + sprintf(arrayname, "_%s", typename->name); + return arrayname; + } + else + return typename->name; +} |