darold / pgFormatter

A PostgreSQL SQL syntax beautifier that can work as a console program or as a CGI. On-line demo site at http://sqlformat.darold.net/
PostgreSQL License
1.68k stars 101 forks source link

Add custom formatting for json_build_object() #261

Closed luukvhoudt closed 3 years ago

luukvhoudt commented 3 years ago

Currently the build-in json_build_object() function is treated like any other function. However this function usually contains a lot of arguments and thus will get unreadable quickly when maintaining regular function formatting.

I would like to suggest to apply custom formatting to the json_build_object() as shown in the expected behavior below.

Expected behavior

select
  json_build_object(
    'foo', 'bar',
    'nested', json_build_object(
      'hello', 'world'
    )
  ) as col1,
  'hello world' as col2;

Actual behavior

select json_build_object('foo', 'bar', 'nested', json_build_object('hello', 'world')) as col1, 'hello world' as col2;
darold commented 3 years ago

pgFormatter is used to format the SQL and plpgsql, formatting of json or other constant is not in the scope.