Unterminated dollar-quoted string at or near "$$
Asked Answered
B

4

6

I'm trying to declare some variables using DBeaver and keep hitting this error.

Unterminated dollar-quoted string at or near "$$

 DO $$
 DECLARE A integer; B integer;

BEGIN   
END$$;

Any ideas?

Bernardabernardi answered 17/9, 2015 at 15:33 Comment(1)
B
4

DBeaver was the issue. Switched to PGAdmin and no more problems.

Bernardabernardi answered 21/9, 2015 at 15:13 Comment(0)
F
6

As of DBeaver 6, you can execute the script with ALT-X (on Windows), which does not attempt to do variable capture/interpolation involving dollar signs.

Frock answered 30/8, 2019 at 15:30 Comment(1)
According to the icons in the editor, alt+x executes the whole script. This is the easier solution, but you can also highlight the entire query and execute the single statement and it won't give any errors.Sportswoman
B
4

DBeaver was the issue. Switched to PGAdmin and no more problems.

Bernardabernardi answered 21/9, 2015 at 15:13 Comment(0)
P
2

The syntax posted is fine. Your problem is that the client application or driver is mangling the query, probably because it doesn't understand dollar-quoting.

It might be trying to split it into separate statements on semicolons, running:

  • DO $$ DECLARE A integer;
  • B integer;
  • BEGIN END$$;

as three separate statements. This would result in the reported error, e.g.

$ psql -c 'DO $$ DECLARE A integer;'
ERROR:  unterminated dollar-quoted string at or near "$$ DECLARE A integer;"
LINE 1: DO $$ DECLARE A integer;
           ^

This is why you must specify your client driver/application when asking questions.


Another possibility with some clients is that it might treat $ as an escaped query-parameter placeholder and replace it with a single $ or try to substitute it for a server-side placeholder like $1. That's not what's happening here, though.

Prepare answered 18/9, 2015 at 4:18 Comment(0)
D
0

DBeaver also gives this error when there is a SQL syntax error in the script. In my case, it was a pair of mismatched parenthesis in a select calculated column.

Dufresne answered 11/2, 2020 at 4:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.