sql-formatter-org / sql-formatter

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

[FORMATTING] Querying a semi-structured data with an element name that is a reserved clause is incorrect #706

Closed chaupow closed 8 months ago

chaupow commented 8 months ago

Hi! ๐Ÿ‘‹

Input data

Which SQL and options did you provide as input? with "language": "snowflake"

SELECT
  details:type
FROM
  transactions

Expected Output

SELECT
  details:type
FROM
  transactions

Actual Output

SELECT
  details:
type
FROM
  transactions

Usage

We're using snowflake and unfortunately some of our JSON fields have the key type which is identified as a reserved clause and incorrectly put in the next line.

We can prevent this by using details:"type" but it would be great if it would work without quotes as well.

This is especially an issue because we would love to use "keywordCase": "upper" but this breaks the query because key names are case sensitive and details:TYPE fails to query the intended lookup.

Thank youuuuuuuuu ๐Ÿ™

nene commented 8 months ago

Thanks for reporting.

Although I apparently have documented this :-syntax of Redshift, I haven't actually implemented any support for it.

Interestingly I just recently fixed a similar issue for Transact-SQL. So most likely some similar solution could be done in here.

nene commented 8 months ago

I was mistaken. This syntax was supported, but as the issue title says, the problem was only the case when a keyword occurred after :.

Now treating : similarly to . that's commonly used as a table.column separator.

nene commented 8 months ago

Fixed in 15.1.3

chaupow commented 8 months ago

Oh wow this was amazing quick!! โšกโœจ

Thanks so much for fixing so promptly and pushing a new version out ๐Ÿฅน I really appreciate it!