From: | Thomas Girault <toma(dot)girault(at)gmail(dot)com> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Module extension for parsing and rewriting functions with infixed syntax |
Date: | 2011-08-06 16:45:32 |
Message-ID: | CAMVHftThKuP4u6qLSuUJ8DC1Z+8gtZ052EmBf+1gkA+R6KaaGw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
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.y
gram.y: conflicts: 84 shift/reduce, 807 reduce/reduce
gram.y: expected 0 shift/reduce conflicts
gram.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
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2011-08-06 17:06:10 | Re: Module extension for parsing and rewriting functions with infixed syntax |
Previous Message | Tom Lane | 2011-08-06 16:23:38 | Re: Reduce WAL logging of INSERT SELECT |