Skip to content

Feature Request: Format jsonb_build_object as key, value #863

Open
@tordans

Description

@tordans

Describe the Feature

When writing JSONB, the standard formatting looks like this…

For me it is a lot easier to read when the key and values share line, like

jsonb_build_object('category', 'intersection_corner', 'size', 5) AS tags,
-- or
  jsonb_build_object(
    'size',
    ((tags ->> 'width')::float / 2)::float,
    'category',
    'driveway',
    'highway',
    tags ->> 'highway',
    'road',
    tags ->> 'road',
    'width',
    tags ->> 'width'
  ) AS tags,
  jsonb_build_object(
    /* sql-formatter-disable */
    'category', 'intersection_corner',
    'size', 5
    /* sql-formatter-enable */
  ) AS tags,
-- and
  jsonb_build_object(
    /* sql-formatter-disable */
    'size', ((tags ->> 'width')::float / 2)::float,
    'category', 'driveway',
    'highway', tags ->> 'highway',
    'road', tags ->> 'road',
    'width', tags ->> 'width'
    /* sql-formatter-enable */
  ) AS tags,

Why do you want this feature?

JSON always uses a key: value pattern to show it's data.
It would be a lot easier for me quickly parse the SQL if the formatter use a similar pattern (even though the jsonb_build_object lists all keys and values in one big list…)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions