Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(postgres-batch-exports): Account for schema being empty string #18254

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions posthog/temporal/workflows/postgres_batch_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def copy_tsv_to_postgres(tsv_file, postgres_connection, schema: str, table_name:
tsv_file.seek(0)

with postgres_connection.cursor() as cursor:
cursor.execute(sql.SQL("SET search_path TO {schema}").format(schema=sql.Identifier(schema)))
if schema:
cursor.execute(sql.SQL("SET search_path TO {schema}").format(schema=sql.Identifier(schema)))
cursor.copy_from(
tsv_file,
table_name,
Expand Down Expand Up @@ -128,6 +129,11 @@ async def insert_into_postgres_activity(inputs: PostgresInsertInputs):
)
with postgres_connection(inputs) as connection:
with connection.cursor() as cursor:
if inputs.schema:
table_identifier = sql.Identifier(inputs.schema, inputs.table_name)
else:
table_identifier = sql.Identifier(inputs.table_name)

result = cursor.execute(
sql.SQL(
"""
Expand All @@ -145,7 +151,7 @@ async def insert_into_postgres_activity(inputs: PostgresInsertInputs):
"timestamp" TIMESTAMP WITH TIME ZONE
)
"""
).format(sql.Identifier(inputs.schema, inputs.table_name))
).format(table_identifier)
)

schema_columns = [
Expand Down
Loading