Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect formatting of bun placeholders (e.g. ?1) #356

Closed
ysmilda opened this issue Jan 17, 2023 · 2 comments · Fixed by #358
Closed

Incorrect formatting of bun placeholders (e.g. ?1) #356

ysmilda opened this issue Jan 17, 2023 · 2 comments · Fixed by #358
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@ysmilda
Copy link
Contributor

ysmilda commented Jan 17, 2023

Describe the bug
In our sql files we make use of placeholders (?0) so that these can be replaced dynamically when read by bun. When ran through sqlfmt it adds a space between the ? and the 0. The following statement "time" = ?0 becomes "time" = ? 0 which makes it invalid.

This is not a feature of standard SQL but I would expect the formatter to leave these statements as is. My assumption is that the ? is read as a statement of it's own, but I can't locate the source of it.

To Reproduce
See example above

Expected behavior
I would expect no formatting to happen between these characters.

Additional context
sqlfmt, version 0.14.3

@tconbeer
Copy link
Owner

Similar to psycopg placeholders #198 and pg variables/placeholders a5d7dd0

Looks like bun's syntax is r"\?\d*", including the bare ?, which collides with the use of ? as an operator in some dialects (we're parsing ? as an operator now). e.g., postgres: jsonb ? text → boolean

But I think we can easily support r"\?\d+" in the other_identifiers rule without any bad side-effects. Change would be here:

Rule(
name="other_identifiers",
priority=600,
pattern=group(
r"@\w+", # stages
r"\$\d+", # pg placeholders
r"\$\w+", # variables
r"%(\([^%()]+\))?s", # psycopg placeholders
),
action=partial(actions.add_node_to_buffer, token_type=TokenType.NAME),
),

@tconbeer tconbeer added enhancement New feature or request good first issue Good for newcomers labels Jan 17, 2023
@tconbeer tconbeer changed the title Incorrect formatting of placeholders. Incorrect formatting of bun placeholders (e.g. ?1) Jan 17, 2023
@ysmilda
Copy link
Contributor Author

ysmilda commented Jan 17, 2023

That indeed did the trick, see #358

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants