Re: [PATCH] Add --syntax to postgres for SQL syntax checking - Mailing list pgsql-hackers

From David G. Johnston
Subject Re: [PATCH] Add --syntax to postgres for SQL syntax checking
Date
Msg-id CAKFQuwZ7naoOgt7BiQPz-+fDievPD0StmaHi6O+zB4DytynRbw@mail.gmail.com
Whole thread Raw
In response to Re: [PATCH] Add --syntax to postgres for SQL syntax checking  (walther@technowledgy.de)
Responses Re: [PATCH] Add --syntax to postgres for SQL syntax checking
Re: [PATCH] Add --syntax to postgres for SQL syntax checking
List pgsql-hackers
On Wed, May 15, 2024 at 12:18 PM <walther@technowledgy.de> wrote:
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


I'm with the original patch idea at this point.  A utility that simply runs text through the parser, not parse analysis, and answers the question: "Were you able to parse this?" has both value and seems like something that can be patched into core in a couple of hundred lines, not thousands, as has already been demonstrated.

Sure, other questions are valid and other goals exist in the ecosystem, but that doesn't diminish this one which is sufficiently justified for my +1 on the idea.

Now, in my ideal world something like this could be made as an extension so that it can work on older versions and not have to be maintained by core.  And likely grow more features over time.  Is there anything fundamental about this that prevents it being implemented in an extension and, if so, what can we add to core in v18 to alleviate that limitation?

David J.

pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: add function argument names to regex* functions.
Next
From: Josef Šimánek
Date:
Subject: Re: [PATCH] Add --syntax to postgres for SQL syntax checking