question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Anonymous Code Block $ Escaping - Error "syntax error at or near "BEGIN""

See original GitHub issue

Hi 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:closed
  • Created 7 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
terehovcommented, Jan 31, 2018

@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. 🧐

0reactions
jeremiahlachicacommented, Nov 19, 2018

@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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found