fix: prevent anonymous code in Postgres (#34412)

(cherry picked from commit 6fc734da51)
This commit is contained in:
Beto Dealmeida
2025-07-31 08:33:34 -04:00
committed by Michael S. Molina
parent 8c9489d72f
commit d8b01c668f
2 changed files with 47 additions and 0 deletions

View File

@@ -382,6 +382,16 @@ class SQLStatement(BaseSQLStatement[exp.Expression]):
if isinstance(node, exp.Command) and node.name == "ALTER":
return True
if (
self._dialect == Dialects.POSTGRES
and isinstance(self._parsed, exp.Command)
and self._parsed.name == "DO"
):
# anonymous blocks can be written in many different languages (the default
# is PL/pgSQL), so parsing them it out of scope of this class; we just
# assume the anonymous block is mutating
return True
# Postgres runs DMLs prefixed by `EXPLAIN ANALYZE`, see
# https://www.postgresql.org/docs/current/sql-explain.html
if (