sql-formatter icon indicating copy to clipboard operation
sql-formatter copied to clipboard

[FORMATTING] Allow dense formatting of multiple square brackets after another

Open primeapple opened this issue 3 years ago • 2 comments

Input data

Which SQL and options did you provide as input?

select foo['bar']['baz']['boz']

Expected Output

select
  foo['bar']['baz']['boz']

Actual Output

select
  foo['bar'] ['baz'] ['boz']

Usage

  • How are you calling / using the library?
    • I used the demo website
  • What SQL language(s) does this apply to?
    • I tested with Snowflake and Postgresql
  • Which SQL Formatter version are you using?
    • The latest one.

Infos

This is not breaking, afaik it works with spaces in between as well. However it looks a bit weird, so maybe we can figure this out?

primeapple avatar Oct 04 '22 07:10 primeapple

Sorry for the late reply. It's definitely a bug.

There are likely several bugs in the handling of square brackets, as there have been many over time. Plus there is quite a bit of syntax variation between dialects as that's not part of standard SQL syntax. Will need to analyze this all more deeply to better understand this whole area of syntax to come up with a more solid solution.

nene avatar Oct 05 '22 16:10 nene

More examples of how this shows up (unexpected spaces):

SELECT '{1,2,3}'::INT []
SELECT foo [1:2]
SELECT foo -> 'bar' -> 'baz'

Expected:

SELECT '{1,2,3}'::INT[]
SELECT foo[1:2]
SELECT foo->'bar'->'baz'

felixfbecker avatar Apr 18 '24 19:04 felixfbecker