Hello,
I am working on a PostgreSQL extension module which defines new
grammar rules completing the classical SQL syntax defined in the
src/backend/parser/gram.y file.
Basically, I want to handle predicates having an infixed syntax { X IS
Y } and rewrite them as classical Boolean functions with prefixed
syntax { Y(X) }.
For instance, the following query :SELECT * FROM cars WHERE cars.color IS yellow;
would be rewritten into :SELECT * FROM cars WHERE yellow(cars.color);
The new predicate could be rewritten as a plpgsql Boolean function
with an unique argument (cars.color IS yellow --> yellow(cars.color)).
I have then added the following rule to the "func_expr" definition
(see gram.y:10280 in postgresql-9.1beta3 source code) :
func_expr:
...| func_arg_expr IS func_name over_clause { FuncCall *n = makeNode(FuncCall); n->funcname = $3;
n->args = list_make1($1); n->agg_order = NIL; n->agg_star = FALSE; n->agg_distinct = FALSE;
n->func_variadic = FALSE; n->over = $4; n->location = @1; $$ = (Node *)n; }
...
However, my first attempt leads to the following errors :/usr/bin/bison -d -o gram.c gram.ygram.y: conflicts: 84
shift/reduce,807 reduce/reducegram.y: expected 0 shift/reduce conflictsgram.y: expected 0 reduce/reduce conflicts
How can I avoid this kind of errors without changing the entire grammar?
In addition, I would rather making this new functionality independent
of the original PostgreSQL source code.
Ideally, the new defined bison rules would be defined in an autonomous
module extension.
I have seen that some contrib modules (such as SEG or CUBE) define
separate bison grammar rules.
However, I don't understand yet how such rules integrate with the
gram.y file without any conflicts.
Can I define my new bison rules separately of the gram.y file?
Can I use the new functionality dynamically after loading an extension
module (LOAD 'MY_EXTENSION';)?
I am new in the PostgreSQL community and any ideas for solving these
problems would be very helpful.
Thanks by advance,
Thomas Girault