Today, a bug in a development version of Hibernate 6.0 reminded me of problem that Firebird has with query expressions, specifically with parentheses around selects.

Specifically, SQL:2016 specifies the following:

```
<query expression> ::=
  [ <with clause> ] <query expression body>
  [ <order by clause> ] [ <result offset clause> ] [ <fetch first clause> ]

<query expression body> ::=
    <query term>
  | <query expression body> UNION [ ALL | DISTINCT ]
      [ <corresponding spec> ] <query term>
  | <query expression body> EXCEPT [ ALL | DISTINCT ]
      [ <corresponding spec> ] <query term>

<query term> ::=
    <query primary>
  | <query term> INTERSECT [ ALL | DISTINCT ]
      [ <corresponding spec> ] <query primary>

<query primary> ::=
    <simple table>
  | <left paren> <query expression body>
[ <order by clause> ] [ <result offset clause> ] [ <fetch first clause> ]
      <right paren>

<simple table> ::=
    <query specification>
  | <table value constructor>
  | <explicit table>

<query specification> ::=
  SELECT [ <set quantifier> ] <select list> <table expression>

<table expression> ::=
  <from clause>
    [ <where clause> ]
    [ <group by clause> ]
    [ <having clause> ]
    [ <window clause> ]
```

If I follow the grammar in parse.y correctly, the problem is that in Firebird, <query primary> is basically <query specification>, so it's missing the following alternative:

```
<left paren> <query expression body>
  [ <order by clause> ] [ <result offset clause> ] [ <fetch first clause> ]
  <right paren>
```

Now I wonder, what would be necessary to introduce this alternative? Would this be a matter of adding the right alternative and adding the order by and offset/fetch info to the RseNode returned by the query expression, or would more be needed?

Mark
--
Mark Rotteveel


Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel

Reply via email to