Skip to content

Commit

Permalink
fix(postgres-batch-exports): Account for schema being empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasfarias committed Oct 27, 2023
1 parent ac2e49d commit f5ccc6b
Showing 1 changed file with 8 additions and 2 deletions.
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

0 comments on commit f5ccc6b

Please sign in to comment.