Repository navigation
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
paren_exprprinter 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:is formatted as
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 forDISTINCT (...)(#32, #73). Parentheses around other single arguments are still removed (my_func((id), (name))still becomesmy_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 testpasses (1060 passed, 1 skipped), as doyarn ts:checkandprettier --checkon the changed files.I found this by formatting the statements of PostgreSQL's regression tests with the
postgresqlparser and comparing the libpg_query parse tree of each output with that of the input.