From fafa15a82d16302c25fd4c361a2747c5c6b1710d Mon Sep 17 00:00:00 2001 From: pnadolny13 Date: Tue, 12 Sep 2023 10:26:09 -0400 Subject: [PATCH] fix column order mismatch using explicit copy into selects --- target_snowflake/connector.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target_snowflake/connector.py b/target_snowflake/connector.py index 8efdc6e..c2bc46e 100644 --- a/target_snowflake/connector.py +++ b/target_snowflake/connector.py @@ -349,10 +349,11 @@ def _get_merge_from_stage_statement( def _get_copy_statement(self, full_table_name, schema, sync_id, file_format): """Get Snowflake COPY statement.""" formatter = SnowflakeIdentifierPreparer(SnowflakeDialect()) + formatted_properties = ", ".join([formatter.format_collation(col) for col in schema["properties"].keys()]) column_selections = self._get_column_selections(schema, formatter) return ( text( - f"copy into {full_table_name} from " + f"copy into {full_table_name} ({formatted_properties}) from " + f"(select {', '.join(column_selections)} from " + f"'@~/target-snowflake/{sync_id}')" + f"file_format = (format_name='{file_format}')"