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

Format of postgresql json in select #542

Closed
tobstarr opened this issue Apr 1, 2020 · 2 comments
Closed

Format of postgresql json in select #542

tobstarr opened this issue Apr 1, 2020 · 2 comments
Milestone

Comments

@tobstarr
Copy link

tobstarr commented Apr 1, 2020

For some reason when accessing json/jsonb structures in a select statement these statements get indented incorrectly:

select id,
       created_at,
       updated_at,
       row->'name',
            row->'age',
                 row->'email'
from users;

The command I am using is sqlformat --reindent --keywords lower --identifiers lower -

Is there something one can do so that result looks like this:

select id,
       created_at,
       updated_at,
       row->'name',
       row->'age',
       row->'email'
from users;

?

@andialbrecht andialbrecht added this to the 0.4.4 milestone Dec 30, 2022
@andialbrecht
Copy link
Owner

See #682

@andialbrecht andialbrecht modified the milestones: 0.4.4, 0.4.5 Mar 20, 2023
@andialbrecht andialbrecht modified the milestones: 0.4.5, 0.5.0 Aug 6, 2023
@andialbrecht
Copy link
Owner

Note, this is "almost" fixed. There's another issue with this concrete example: ROW is a reserved word in MySQL (see https://dev.mysql.com/doc/refman/8.0/en/keywords.html#keywords-8-0-detailed-R). Right now it's not possible to choose a dialect in sqlparse, but we're working on it.
So, right now your example still doesn't work as expected, but it would work on columns with other names, for example:

>>> sql = """select id,
...        created_at,
...        updated_at,
...        foo -> 'name',
...             foo->'age',
...                  foo -> 'email'
... from users;"""
>>>
>>> print(sqlparse.format(sql, reindent=True))
select id,
       created_at,
       updated_at,
       foo -> 'name',
       foo->'age',
       foo -> 'email'
from users;
>>>

andialbrecht added a commit that referenced this issue Mar 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants