Alternative variable syntax that's compatible with SQL formatters
See original GitHub issueI’d like to explore the idea of changing PgTyped to use syntax that is valid SQL, so that it can be formatted by SQL formatters that are standard compliant. At the moment I’m finding most SQL formatters get tripped up by the :foo
and particularly the :foo!
syntax.
Are there any ideas for alternative variable placeholder syntax that would stay SQL compliant? The best idea I’ve had is to use quoted identifier syntax (e.g. ":id!"
), but unfortunately this is still a syntax error for spread scenarios.
FWIW it looks like https://sql-formatter-org.github.io/sql-formatter/ is one of the best out there.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
SQL formatter tools
SQL formatter tools · ApexSQL Refactor · Atom Beautify · dbForge SQL Complete · FSQLF · Poor Man's T-SQL formatter · Rapid Database...
Read more >FORMATMESSAGE (Transact-SQL) - SQL Server
SELECT FORMATMESSAGE('This is the %s and this is the %s.', 'first variable', 'second variable') AS Result;. Returns: ...
Read more >SQL WITH: Organize Complex Queries
The WITH clause adds named subqueries to SQL queries. WITH is also known as Common Table Expression (CTE).
Read more >SQL Prompt: Write, format, analyze and refactor SQL ...
SQL Prompt can find and highlight any parameters or variables that are unused in a script. Access your schema information and view a...
Read more >Script: Alternative Quoting Mechanism (''Q'') for String Literals
Description Oracle Database offers the ability, in both SQL and PL/SQL, to specify our own user-defined delimiters for string literals. Here's ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I just build a tiny wrapper around
sql-formatter
npm package to solve this.I then used
lint-staged
npm package to format my sql files prior to each commit (and also do code autogen at this time):As in include a SQL formatter in pgTyped? My initial reaction is no, as I’m skeptical that there’s enough time from contributors (including yourself) to support that extra surface area, and competing with existing formatters seems like a battle that’s inevitable to lose.
I’m still somewhat optimistic that there’s an alternative syntax we could use that would be SQL compatible as well being something pgTyped could do variable substitution on, I don’t feel confident we’ve explored the full landscape of possibilities.
I’d like to put together a full list of syntax ideas that have been considered, I think that would help me be confident whether there is/isn’t a viable option.