Skip to content
Advertisement

Unterminated dollar quote

How to use IF statement in the PostgreSql (11 version)? I tried just raw IF usage but got problem (syntax error at or near “IF”). To resolve this problem people propose to use ‘do &&’ but it does not work as well (Unterminated dollar quote started at position 3 in SQL DO $$ BEGIN IF ……). Here is my SQL code:

All I need is to create table and insert some init data to it if table does not exist.

Advertisement

Answer

Some platforms do not support dollar quoting. In your specific example you should have a semicolon after the last END. You may need to add a DECLARE statement also.

For platforms that don’t recognize dollar quoting you can use ' instead. You’ll need to escape any ' in the body of the anonymous function though.

Like so:

DBFiddle to view a working example.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement