[FIX] pglogical: don't replicate aggregate functions

This commit is contained in:
Holger Brunn
2022-08-18 15:08:23 +02:00
parent 49bcac937b
commit 927c50bd09

View File

@@ -14,6 +14,7 @@ DDL_KEYWORDS = set(["CREATE", "ALTER", "DROP", "TRUNCATE"])
QUALIFY_KEYWORDS = DDL_KEYWORDS | set(["FROM", "INHERITS", "JOIN"]) QUALIFY_KEYWORDS = DDL_KEYWORDS | set(["FROM", "INHERITS", "JOIN"])
NO_QUALIFY_KEYWORDS = set(["AS", "COLUMN", "ON", "RETURNS", "SELECT"]) NO_QUALIFY_KEYWORDS = set(["AS", "COLUMN", "ON", "RETURNS", "SELECT"])
TEMPORARY = set(["TEMP", "TEMPORARY"]) TEMPORARY = set(["TEMP", "TEMPORARY"])
FUNCTION_LIKE = set(["FUNCTION"])
def schema_qualify(tokens, temp_tables, keywords=None, schema="public"): def schema_qualify(tokens, temp_tables, keywords=None, schema="public"):
@@ -55,11 +56,14 @@ def schema_qualify(tokens, temp_tables, keywords=None, schema="public"):
needs_qualification &= ( needs_qualification &= (
keywords and (keywords[-1] in QUALIFY_KEYWORDS) or False keywords and (keywords[-1] in QUALIFY_KEYWORDS) or False
) )
# and also not if this is a temporary table # and also not if this is a temporary table or a function
if needs_qualification: if needs_qualification:
if len(keywords) > 1 and keywords[-2] in TEMPORARY: if len(keywords) > 1 and keywords[-2] in TEMPORARY:
needs_qualification = False needs_qualification = False
temp_tables.append(str_token) temp_tables.append(str_token)
elif len(keywords) > 0 and keywords[-1] in FUNCTION_LIKE:
# don't qualify function or names
needs_qualification = not token.within(Parenthesis)
elif str_token in temp_tables: elif str_token in temp_tables:
needs_qualification = False needs_qualification = False
temp_tables.remove(str_token) temp_tables.remove(str_token)
@@ -112,7 +116,7 @@ def post_load():
) and not any( ) and not any(
token.is_keyword and token.normalized in token.is_keyword and token.normalized in
# don't replicate constraints, triggers, indexes # don't replicate constraints, triggers, indexes
("CONSTRAINT", "TRIGGER", "INDEX") ("AGGREGATE", "CONSTRAINT", "TRIGGER", "INDEX")
for parsed in parsed_queries for parsed in parsed_queries
for token in parsed.tokens[1:] for token in parsed.tokens[1:]
): ):