I am trying to pass a query to Snowflake which has the following format:
query = f"""
insert into target
with incoming (id,name,age) as (
select * from
values ()
), another_cte (
....
)
select * from another cte
"""
For the values, I want to pass a list of tuples. For example:
incoming_values = [(1,'john',20),(2,'jane',22)].
I am calling the execute function as:
execute(query, incoming_values)
However, I am running into error: AttributeError: 'tuple' object has no attribute 'replace'\n"
Rather than trying to select from the values as a literal row, insert them into a temporary table in the usual way and use that temporary table in your query. It will make for much cleaner code, here is a full example:
This script prints the following:
[(1, 'john', 20), (2, 'jane', 22), (3, 'simon', 23)]
Don't worry about the creation of a temporary table, once the Snowflake session ends (when the program is out of the context manager) the table is cleaned up and gone, it also doesn't use any unnecessary storage costs after it is cleaned up.