diff options
author | Bruce Momjian <bruce@momjian.us> | 1999-12-16 20:07:41 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 1999-12-16 20:07:41 +0000 |
commit | cf374febf5a06dfbf02f5d6d74f5d156cb9af62a (patch) | |
tree | fa9fbf811335762bf0b537239fe0798da59a61e1 /src | |
parent | 99b8f8451170a5c2fc130426952819502c10aea9 (diff) | |
download | postgresql-cf374febf5a06dfbf02f5d6d74f5d156cb9af62a.tar.gz postgresql-cf374febf5a06dfbf02f5d6d74f5d156cb9af62a.zip |
>Turning nextval and currval into keywords is not an acceptable way to
>go about this. That will risk breaking existing applications that use
>those names as column names.
>
>It should actually almost work to write sq.nextval as things stand,
>because Postgres has for a long time considered table.function and
>function(table) to be interchangeable notations for certain kinds of
>functions. nextval doesn't seem to be one of that kind of function,
>at the moment. I'd suggest leaving the grammar as it was, and taking a
>look at ParseFuncOrColumn in parse_func.c to see if you can't persuade
>it to accept the sequence functions in that style.
OK, good point. I tried to implement it somewhere else and ended up
extending transformAttr. Attached you'll find the patch.
Jeroen van Vianen
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/parser/parse_expr.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c index ee43be41950..5b50de1494b 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.60 1999/12/10 07:37:35 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.61 1999/12/16 20:07:41 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -531,6 +531,30 @@ static Node * transformAttr(ParseState *pstate, Attr *att, int precedence) { Node *basenode; + char * attribute; + + /* Get the name of the first attribute */ + if ((att != NULL) && (lfirst(att->attrs) != NULL)) + { + /* + * Special case for name.nextval and name.currval, assume it's a + * sequence and transform to function call to nextval('name') and + * currval('name') + */ + attribute = pstrdup(((Value *) lfirst(att->attrs))->val.str); + if ((strcasecmp(attribute, "nextval") == 0) || + (strcasecmp(attribute, "currval") == 0)) + { + Value *s = makeNode(Value); + + s->type = T_String; + s->val.str = att->relname; + + return ParseFuncOrColumn(pstate, attribute, + lcons(make_const(s), NIL), false, false, + &pstate->p_last_resno, precedence); + } + } basenode = ParseNestedFuncOrColumn(pstate, att, &pstate->p_last_resno, precedence); |