Anonymous Code Block $ Escaping - Error "syntax error at or near "BEGIN""
See original GitHub issueHi I’m trying to perform an anonymous code block, but having issues which I believe may be related to escaping bind parameters/parameterized query
Using Postgres 9.5
This works fine when using a non parameterized query and less the escaping of the dollar signs (which I believe I have done incorrectly) on the DO
and END
, so curious why I receive the error, “syntax error at or near “BEGIN”” on the query below. I hope it is a simple matter of not escaping the dollar signs correctly, but I’m not sure.
DO $$$$
BEGIN
IF EXISTS (
SELECT id
FROM mytable mt
WHERE mt.name = "ScrappyDoo"
)
THEN
INSERT INTO myothertable (type, name) VALUES ($1, $2);
ELSE
INSERT INTO myothertable (type, name) VALUES ($1, $2);
END IF;
END $$$$;
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (1 by maintainers)
Top Results From Across the Web
PostgreSQL {call Update Set ...} getting "syntax error at or ...
An UPDATE statement can't be executed with a CallableStatement. A CallableStatement is essentially only intended to call stored procedures.
Read more >Syntax error on declaring a variable inside a transaction
Try using a declare block before the main block: DECLARE -- declarations go here BEGIN -- commands go here END;.
Read more >Documentation: 15: 43.2. Structure of PL/pgSQL
A common mistake is to write a semicolon immediately after BEGIN . This is incorrect and will result in a syntax error. A...
Read more >Closures — The Swift Programming Language (Swift 5.7)
Closures are self-contained blocks of functionality that can be passed around and used in your code. Closures in Swift are similar to blocks...
Read more >Arrow function expressions - JavaScript - MDN Web Docs
Let's decompose a traditional anonymous function down to the simplest arrow function ... so the code above would be a syntax error.
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 FreeTop 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
Top GitHub Comments
@charmander Thank you so much for your efforts! We literally just figured out the problem. There were some invisible utf8 chars hiding, that apparently sneaked in with a copy&paste. 🧐
this has solved my problem too. I had make sure there was no extra ut8 chars hiding. Thanks!