Обсуждение: Possible to modify query language in an extension?

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

Possible to modify query language in an extension?

От
Chris Cleveland
Дата:
Noob here. I'm getting started on building a Postgres extension.

I'd like to add some keywords/clauses to the SELECT statement. For my particular application, the syntax with new keywords would be way better than trying to do it through functions alone. I would add some new keywords followed by expressions similar to those allowed in WHERE and GROUP BY clauses. The new SELECT would return multiple result sets.

I did find an example where someone did modify the parser: http://www.neilconway.org/talks/hacking/hack_slides.pdf

Question: is it possible to do this in an extension? Or do I have to fork the Postgres codebase itself?

Obviously, I'd prefer the former. Forks are bad.

Re: Possible to modify query language in an extension?

От
Tom Lane
Дата:
Chris Cleveland <ccleve+github@dieselpoint.com> writes:
> I'd like to add some keywords/clauses to the SELECT statement.

Yeah, you'll have to modify gram.y (and a pile of other places)
if you want to do that.  That's certainly something we do all
the time, but bison doesn't provide any way to add grammar
productions on-the-fly, so it does imply core-code mods.

> ... The new SELECT would return multiple result sets.

And that sounds like you'd also be redefining the wire protocol,
hence having to touch client-side code as well as the server.

            regards, tom lane


Re: Possible to modify query language in an extension?

От
Robert Haas
Дата:
On Sun, Mar 17, 2019 at 12:21 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Chris Cleveland <ccleve+github@dieselpoint.com> writes:
> > I'd like to add some keywords/clauses to the SELECT statement.
>
> Yeah, you'll have to modify gram.y (and a pile of other places)
> if you want to do that.  That's certainly something we do all
> the time, but bison doesn't provide any way to add grammar
> productions on-the-fly, so it does imply core-code mods.
>
> > ... The new SELECT would return multiple result sets.
>
> And that sounds like you'd also be redefining the wire protocol,
> hence having to touch client-side code as well as the server.

Long story short, this sounds like a VERY hard project.  Chris, you
will probably want to think about some other approach to achieving
your objective, because this sounds like a project that even an expert
coder would spend a lot of time trying to get done.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company