sql-formatter-org / sql-formatter

A whitespace formatter for different query languages
https://sql-formatter-org.github.io/sql-formatter/
MIT License
2.31k stars 399 forks source link

Feature Request: Detect / Format parameters included in SQL statement #768

Open ghedwards opened 1 month ago

ghedwards commented 1 month ago

Describe the Feature Detect / Format parameters included in SQL statement

Such as SELECT * FROM test = ? parameters: ['foo']

Why do you want this feature? Some tools / logging output queries with the parameters listed at the end of the statement, this enhancement would allow formatting this type of SQL anywhere without direct access to the API, like in VSCode for example.

I'm happy to help with the code on this if its likely to be merged as a pull request.

nene commented 1 month ago

Thanks for the feature suggestion.

I'm unsure about this. On one hand I'm cautious of supporting anything that's beyond plain SQL. On another hand various SQL dialects include stuff that's quite far from what's in SQL standard.

For start, could you perhaps name some concrete examples of the tools that produce such output. I have personally zero familiarity with such tools. And how much variance is there between different tools that do this (like do they all use the exact same syntax for this, or will there be major differences or something in between).

Regarding the implementation, at least for start I would make support of this an opt-in feature. I do welcome a pull request for this, as I'm very unlikely to implement it on my own. But I can give guidance if needed.

Last, but not least, what sort of output would you expect from the formatter when it detects these parameters?

ghedwards commented 1 month ago

@nene tools such as Glowroot and / or Opentelemetry