Обсуждение: gram.y

Поиск
Список
Период
Сортировка

gram.y

От
Sferacarta Software
Дата:
Hi all,

I'm trying to make parser recognize SELECTs between parenthesis.
I need to do this work to have m$access working with PostgreSQL.
The micro$oft access jet (great wisdom) translates the UNIONs as:
(SELECT ...) UNION (SELECT ...)
To have PostgreSQL understand this syntax I edited gram.y
and I modified the "SelectStmt:" and the "SubUnion:" as:

SelectStmt: opt_left_paren SELECT                          opt_unique                          res_target_list2
                result                          from_clause                          where_clause
  group_clause                          having_clause           opt_right_paren                          union_clause
                      sort_clause                               {                                       SelectStmt *n
=makeNode(SelectStmt);                                       n->unique       = $3;
n->targetList   = $4;                                       n->into         = $5;
n->fromClause  = $6;                                       n->whereClause  = $7;
n->groupClause = $8;                                       n->havingClause = $9;
n->unionClause = $11;                                       n->sortClause   = $12;
$$ = (Node *)n;                               }               ;
 

SubUnion: opt_left_paren SELECT opt_unique res_target_list2                        from_clause where_clause
          group_clause having_clause opt_right_paren                               {
  SelectStmt *n   = makeNode(SelectStmt);                                       n->unique       = $3;
                   n->unionall     = FALSE;                                       n->targetList   = $4;
                     n->fromClause   = $5;                                       n->whereClause  = $6;
                    n->groupClause  = $7;                                       n->havingClause = $8;
                   $$ = (Node *)n;                               }               ;
 


and now with these changes I can specify SELECTs inside () and
without parenthesis as before, I tried also subselects and seems that
all works well...but when I tried a select with a function which contains
parenthesis, like SUM(), VERSION() for example, then it doesn't work anymore.
I'm not very good programing in C.
Is there anybody that can help me with this question ?
Any help would be very appreciated.

EXAMPLES:

(select (2-3)*3);
?column?
--------     -3
(1 row)

(select (132-3)*3)  union all ( select ((983+1)/2) );
?column?
--------    387    492
(2 rows)

select (132-3)*3  union all  select ((983+1)/2);
?column?
--------    387    492
(2 rows)

select ename from emp where ename in (    select ename from emp where ename like 'K%'    );
ename
-----
KING
(1 row)

select version();
ERROR:  parser: parse error at or near "("

-Jose'-




Re: [HACKERS] gram.y

От
"Thomas G. Lockhart"
Дата:
> I'm trying to make parser recognize SELECTs between parenthesis.
> I need to do this work to have m$access working with PostgreSQL.
> The micro$oft access jet (great wisdom) translates the UNIONs as:
> (SELECT ...) UNION (SELECT ...)

OK, just assume I have mentioned that you should ask M$ to support
standard syntax. It isn't entirely clear from the BNF definition of
SQL92 (parens near SELECT are allowed in some places), but I was hard
pressed to see where this was legal syntax.

> To have PostgreSQL understand this syntax I edited gram.y
> and I modified the "SelectStmt:" and the "SubUnion:" as:
> SelectStmt: opt_left_paren SELECT
<snip>

One problem with this is the parens must of course be balanced, so
making them individually optional is probably not the right thing to do.
Just to experiment I tried adding parens on some of the several places
where selects with unions are allowed, and started running into trouble
on the second one I tried. I'm guessing that a yacc-based parser will
run into serious trouble, but I haven't thought of a completely fatal
example yet.

Also, the way gram.y is currently laid out it would be difficult to
ensure that all clauses of the UNION are surrounded by parens if one
clause has those parens. But I think this would be desirable if the
parens are going to be allowed at all.
                     - Tom


Re[2]: [HACKERS] gram.y

От
Sferacarta Software
Дата:
Hello Thomas,

domenica, 6 dicembre 98, you wrote:

>> I'm trying to make parser recognize SELECTs between parenthesis.
>> I need to do this work to have m$access working with PostgreSQL.
>> The micro$oft access jet (great wisdom) translates the UNIONs as:
>> (SELECT ...) UNION (SELECT ...)

TGL> OK, just assume I have mentioned that you should ask M$ to support
TGL> standard syntax. It isn't entirely clear from the BNF definition of
TGL> SQL92 (parens near SELECT are allowed in some places), but I was hard
TGL> pressed to see where this was legal syntax.

The problem is: I can't say this syntax is illegal, I can't find
nothing about it on SQL documentation.

Any way. I think it would be interesting to have parser recognize every
statement enclosed into parens.
I have also Informix-SE on my Linux box, I tried statements enclosed
into parens and Informix understand it.

-Jose'-