[IMP] use sqlparse also to determine which ddl to update

This commit is contained in:
Holger Brunn
2022-05-17 10:42:16 +02:00
parent 377aa43832
commit d431ee796c

View File

@@ -41,12 +41,17 @@ def post_load():
def execute(self, query, params=None, log_exceptions=None): def execute(self, query, params=None, log_exceptions=None):
"""Wrap DDL in pglogical.replicate_ddl_command""" """Wrap DDL in pglogical.replicate_ddl_command"""
parsed_queries = [x.get_type() for x in sqlparse.parse(query)] # short circuit statements that must be as fast as possible
if any(q in ["CREATE", "ALTER", "DROP"] for q in parsed_queries) and ( if query[:6] != "SELECT":
parsed_queries = sqlparse.parse(query)
if any(
parsed_query.get_type() in ("CREATE", "ALTER", "DROP")
for parsed_query in parsed_queries
) and not any(
token.is_keyword and token.normalized in
# don't replicate constraints, triggers, indexes # don't replicate constraints, triggers, indexes
"CONSTRAINT" not in query ("CONSTRAINT", "TRIGGER", "INDEX")
and "TRIGGER" not in query for parsed in parsed_queries for token in parsed.tokens[1:]
and "INDEX" not in query
): ):
mogrified = self.mogrify(query, params).decode("utf8") mogrified = self.mogrify(query, params).decode("utf8")
query = "SELECT pglogical.replicate_ddl_command(%s, %s)" query = "SELECT pglogical.replicate_ddl_command(%s, %s)"