Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FORMATTING] Missing space after colon in JSON_OBJECT(key: value) #761

Open
felixfbecker opened this issue Jul 23, 2024 · 1 comment
Open
Labels

Comments

@felixfbecker
Copy link

When you use the JSON_OBJECT() function from the SQL standard (implemented in PostgreSQL 16), the formatter removes/does not insert a space between the : delimiting the key and value, which makes the SQL somewhat hard to read.

Input data

Which SQL and options did you provide as input?

SELECT JSON_OBJECT(
  'key': 'value',
  'key2': my_table.my_column
)

Expected Output

SELECT JSON_OBJECT(
  'key': 'value',
  'key2': my_table.my_column
)

Actual Output

SELECT JSON_OBJECT(
  'key':'value',
  'key2':my_table.my_column
)

This may not seem that big of a deal for a simple example like this, but when the value is a more complicated expression with nested objects etc it becomes much worse.

Usage

  • How are you calling / using the library? Prettier
  • What SQL language(s) does this apply to? PostgreSQL but presumably all DBs that support JSON_OBJECT()
  • Which SQL Formatter version are you using? 15.0.2
@nene
Copy link
Collaborator

nene commented Jul 24, 2024

Thanks for reporting.

This dense formatting of : is currently done to improve the formatting of array-slice operations (related to #624):

SELECT foo[1:5];

Unfortunately this is tricky to fix with the current architecture. When I improve it for JSON_OBJECT, it'll become worse for array-slice.

There's much more hope of doing better JSON_OBJECT() formatting in prettier-plugin-sql-cst where it currently though produces a hard crash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants