fakesnow
fakesnow copied to clipboard
executemany raises TypeError: not all arguments converted during string formatting
fakesnow 0.9.27
snowflake-connector-python 3.13.2
import fakesnow
import snowflake.connector
with fakesnow.patch():
with snowflake.connector.connect() as conn1, conn1.cursor() as cur:
cur.execute("create database TEST_DB")
cur.execute("USE DATABASE TEST_DB")
cur.execute("create schema TEST_DB.TEST")
cur.execute("USE SCHEMA TEST_DB.TEST")
sql = """
create
or replace TABLE TT (
TESTCOL VARCHAR(16777216)
);
"""
cur.execute(sql)
sql_i = 'INSERT INTO TT(TESTCOL) SELECT column1 FROM VALUES (?)'
rows = [('asdf')]
cur.executemany(
sql_i,
rows
)
Results:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_16876\938354573.py in <module>
22 rows = [('asdf')]
23
---> 24 cur.executemany(
25 sql_i,
26 rows
~\Anaconda3\lib\site-packages\fakesnow\cursor.py in executemany(self, command, seqparams, **kwargs)
377 # query one by one, which means the response differs
378 for p in seqparams:
--> 379 self.execute(command, p)
380
381 return self
~\Anaconda3\lib\site-packages\fakesnow\cursor.py in execute(self, command, params, *args, **kwargs)
137
138 command = self._inline_variables(command)
--> 139 command, params = self._rewrite_with_params(command, params)
140 if self._conn.nop_regexes and any(re.match(p, command, re.IGNORECASE) for p in self._conn.nop_regexes):
141 transformed = transforms.SUCCESS_NOP
~\Anaconda3\lib\site-packages\fakesnow\cursor.py in _rewrite_with_params(self, command, params)
446 params = tuple(convert(v) for v in params)
447
--> 448 return command % params, None
449
450 return command, params
TypeError: not all arguments converted during string formatting
We use this insert format as it is useful for handling JSON and such.
In the above example you are using the question mark (qmark) paramater style but the default is pyformat.
And so you'll get the same error on a real Snowflake instance.
To use qmark, you need to set this before or in the connection, see here. Alternatively you can use %s instead of ? in the query string.
Could you also provide what you expect the contents of the table TT to look like after the query is run?
The snowflake python connector behaviour differs based on whether you use qmark or pyformat.
Closing as the behaviour here is expected.