diff --git a/src/Codeception/Lib/Driver/PostgreSql.php b/src/Codeception/Lib/Driver/PostgreSql.php
index <HASH>..<HASH> 100644
--- a/src/Codeception/Lib/Driver/PostgreSql.php
+++ b/src/Codeception/Lib/Driver/PostgreSql.php
@@ -28,8 +28,11 @@ class PostgreSql extends Db
                 continue;
             }
 
-            if (strpos(trim($sqlLine), '$$') === 0) {
-                $dollarsOpen = !$dollarsOpen;
+            if (!preg_match('/\'.*\$\$.*\'/', $sqlLine)) { // Ignore $$ inside SQL standard string syntax such as in INSERT statements.
+                $pos = strpos($sqlLine, '$$');
+                if (($pos !== false) && ($pos >= 0)) {
+                    $dollarsOpen = !$dollarsOpen;
+                }
             }
 
             $query .= "\n" . rtrim($sqlLine);
Enhance dollar quoting ($$) processing

Fix Codeception/Codeception#<I>
The old code handled dollar-quoted blocks only if the $$ is at the beginning of a new line. This enhancement detects it anywhere and also detects if the $$ is part of a SQL standard string and ignores it.