Format of postgresql json in select
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;
?
See #682
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;
>>>