Skip to content

Keep parentheses around row constructors in function arguments - #96

Open
wleeaf wants to merge 1 commit into
nene:masterfrom
wleeaf:keep-row-constructor-arg-parens
Open

wleeaf wants to merge 1 commit into
nene:masterfrom
wleeaf:keep-row-constructor-arg-parens

Conversation

@wleeaf

@wleeaf wleeaf commented Oct 25, 2026

Copy link
Copy Markdown

The paren_expr printer drops parentheses around a function argument. When the parentheses hold a list, the list is a single row constructor, so dropping them turns one argument into several and changes which function is called:

SELECT array_position(ids, (1, 1)) FROM tbl

is formatted as

SELECT array_position(ids, 1, 1) FROM tbl

This is a different call: array_position(anyarray, anyelement, integer) with a start position, instead of searching for the row (1, 1).

The parentheses are now kept when they contain a list_expr, the same way they are already kept for subqueries and for DISTINCT (...) (#32, #73). Parentheses around other single arguments are still removed (my_func((id), (name)) still becomes my_func(id, name)).

Test: "preserves parenthesis around row constructor inside function arguments" in test/expr/expr.test.ts (PostgreSQL). It fails without the change and passes with it. yarn test passes (1060 passed, 1 skipped), as do yarn ts:check and prettier --check on the changed files.

I found this by formatting the statements of PostgreSQL's regression tests with the postgresql parser and comparing the libpg_query parse tree of each output with that of the input.

The paren_expr printer drops parentheses around a function argument.
When the argument is a parenthesized list, that list is a single row
constructor, so dropping the parentheses turns one argument into
several and changes the call:

    SELECT array_position(ids, (1, 1)) FROM tbl

was formatted as

    SELECT array_position(ids, 1, 1) FROM tbl

The parentheses are now kept when they contain a list expression, as
they already are for subqueries and DISTINCT.
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

Successfully merging this pull request may close these issues.

1 participant