Recursive query syntax ambiguity
Recursive query syntax ambiguity
От:
Gregory Stark <stark@enterprisedb.com>
Дата:
Woah, I just realized it's much worse than that. I think the syntax in the ANSI is not parsable in LALR(1) at all. Note the following: WITH RECURSIVE foo (a,b) AS (subq) SEARCH BREADTH FIRST BY a,b,c(x,z),d(y,z) AS (subq) SELECT ... To determine whether "c" is the name of a new it has to scan as far ahead as the "," before the "d". Note that "d" here is in fact not part of the at all, it's the name of a second . bleagh. -- Gregory Stark EnterpriseDB http://www.enterprisedb.com
Re: Recursive query syntax ambiguity
От:
Andrew Dunstan <andrew@dunslane.net>
Дата:
Gregory Stark wrote: > Woah, I just realized it's much worse than that. I think the syntax in the > ANSI is not parsable in LALR(1) at all. Note the following: > > WITH RECURSIVE foo (a,b) AS (subq) SEARCH BREADTH FIRST BY a,b,c(x,z),d(y,z) AS (subq) SELECT ... > > To determine whether "c" is the name of a new it has to > scan as far ahead as the "," before the "d". Note that "d" here is in fact not > part of the at all, it's the name of a second element>. > > bleagh. > > Can you post the rules you have so far that you're playing around with? (Also maybe the rules from the standard - I don't have a copy handy). cheers andrew
Re: Recursive query syntax ambiguity
"Andrew Dunstan" writes:
> Can you post the rules you have so far that you're playing around with? (Also
> maybe the rules from the standard - I don't have a copy handy).
This is the best compromise I've come up with so far. It makes CYCLE a
reserved word and requires a CYCLE clause if there's a SEARCH clause.
Here are the grammar rules from the spec (I've attached PDFs of the syntax
pages for the two productions I'm describing since the text copy/paste comes
out pretty poorly)
7.13
Function
Specify a table.
Format
::=
[ ]
::=
WITH [ RECURSIVE ]
::=
[ { }... ]
::=
[ ]
AS [ ]
::=
::=
| UNION [ ALL | DISTINCT ]
[ ]
| EXCEPT [ ALL | DISTINCT ]
[ ]
::=
| INTERSECT [ ALL | DISTINCT ]
[ ]
::=
|
::=
| Re: Recursive query syntax ambiguity
От:
Martijn van Oosterhout <kleptog@svana.org>
Дата:
Ok, looking at your example: WITH RECURSIVE foo (a,b) AS (subq) SEARCH BREADTH FIRST BY a,b , c(x,z),d(y,z) AS (subq) SELECT ... What you're trying to say is that the c is a , not a . But the parser will see that as soon as it hits the open parenthesis, since a is always just a column name. Also, the AS is the doesn't appear to be optional, I assume you left that out after the c(x,z) for clarity. I think bison should be able to handle this as long as the "name" in common_table_expression matches exactly the same things as whatever columnList uses. It can the merge the two parse paths, allowing it to "see" further. Have a nice day, -- Martijn van Oosterhout http://svana.org/kleptog/ > From each according to his ability. To each according to his ability to litigate.