Re: [PATCH] Add --syntax to postgres for SQL syntax checking

From: walther(at)technowledgy(dot)de
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Josef Šimánek <josef(dot)simanek(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH] Add --syntax to postgres for SQL syntax checking
Date: 2024-05-15 19:18:41
Message-ID: b4429432-2a90-49e3-b963-dac8b19fd87e@technowledgy.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane:
>> This is really what is missing for the ecosystem. A libpqparser for
>> tools to use: Formatters, linters, query rewriters, simple syntax
>> checkers... they are all missing access to postgres' own parser.
>
> To get to that, you'd need some kind of agreement on what the syntax
> tree is. I doubt our existing implementation would be directly useful
> to very many tools, and even if it is, do they want to track constant
> version-to-version changes?

Correct, on top of what the syntax tree currently has, one would
probably need:
- comments
- locations (line number / character) for everything, including those of
comments

Otherwise it's impossible to print proper SQL again without losing
information.

And then on top of that, to be really really useful, you'd need to be
able to parse partial statements, too, to support all kinds of "language
server" applications.

Tracking version-to-version changes is exactly the reason why it would
be good to have that from upstream, imho. New syntax is added in
(almost?) every release and everyone outside core trying to write their
own parser and staying up2date with **all** the new syntax.. will
eventually fail.

Yes, there could be changes to the produced parse tree as well and you'd
also need to adjust, for example, your SQL-printers. But it should be
easier to stay up2date than right now.

Best,

Wolfgang

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2024-05-15 19:19:39 Re: Incorrect Assert in BufFileSize()?
Previous Message Tom Lane 2024-05-15 19:10:08 Re: add function argument names to regex* functions.