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

Support Bracketed Literals (SQL Server) #514

Open
jlkravitz opened this issue Oct 26, 2023 · 2 comments
Open

Support Bracketed Literals (SQL Server) #514

jlkravitz opened this issue Oct 26, 2023 · 2 comments
Labels
bug Something isn't working sqlserver-only

Comments

@jlkravitz
Copy link

Describe the bug
When referencing a linked server in openquery in SQL Server, sqlfmt incorrectly formats linked server names that are in brackets (with uncommon characters). In my case, the name of the linked server is the server's IP address (xxx.xx.xxx.xx). It adds unnecessary spaces. The resulting SQL has a syntax error and does not run.

To Reproduce

select * from openquery([123.23.54], 'select * from my_table')

Expected behavior

select * from openquery([123.23.54], 'select * from my_table')

Actual behavior

select * from openquery([123.23 .54], 'select * from my_table')

Additional context
What is the output of sqlfmt --version?

sqlfmt, version 0.19.2
@tconbeer
Copy link
Owner

Thanks for the report.

SQL Server uses brackets in a unique way (compared to all other databases/warehouses). To support this we would need to create a new SQL Server-specific dialect that treats brackets like quotes. I'm unlikely to get that done any time soon, but PRs are welcome!

@tconbeer tconbeer added sqlserver-only bug Something isn't working labels Oct 26, 2023
@jlkravitz
Copy link
Author

Got it. Your comment has made me explore, and I found out I can wrap the name in double-quotes instead of brackets. sqlfmt then works like a charm!

@tconbeer tconbeer changed the title Formatting Linked Server Name Support Bracketed Literals (SQL Server) Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sqlserver-only
Projects
None yet
Development

No branches or pull requests

2 participants