A method to prepare a database query or command and execute it against all parameters found in a sequence or mapping of parameters.
Questions tagged [executemany]
135 questions
2
votes
1 answer
INSERT FOREIGN KEY in another table with executemany() in PostgreSQL
I tried to insert row values for code column in statements table as a foreign key from companies Table. i took the following steps:
Creating Tables
cur.execute("CREATE TABLE IF NOT EXISTS companies (code INT NOT NULL PRIMARY KEY, short_name…

T.M
- 93
- 9
2
votes
1 answer
MySQL insert with List Comprehensions
I've been trying to convert most of my mysqlclient execute commands to be done in a single line by making use of List Comprehensions. An example of this is the following snippet:
def org(conn, cursor, target_org=None, target_sid=None):
try:
…

Bernardo Meurer
- 2,295
- 5
- 31
- 52
2
votes
2 answers
python sqlite executemany statement error: ValueError: parameters are of unsupported type
What I want to do seems like it should be pretty straightforward but I just can't get past the errors I'm getting. Basically, I create a list, create a database table and then want to insert the elements of the list into the table. Here's what I've…

Jeff F
- 975
- 4
- 14
- 24
1
vote
2 answers
Update rows if data exists with executemany
I have the following SQL that aims to create a new record in the DB or update an existing one.
sql = """INSERT INTO table (v1, v2, v3, v4, v5, v6)
VALUES (?, ?, ?, ?, ?, ?)
ON CONFLICT(v5) DO UPDATE
SET v1 = ?, v3 = ?, v6…

antpngl92
- 494
- 4
- 12
1
vote
2 answers
Can't update table using "executemany" in python sqlite
I have to update simple table using below expression:
cur.executemany('UPDATE earths SET population=?, density=?, tilt=?, "land area"=?, dobe=?, livity=? WHERE sid=' + str(dc['sid']) + ' AND nr=' + str(dc['nr']), v)
Printing the content it…

Peter.k
- 1,475
- 23
- 40
1
vote
0 answers
pyodbc.DataError: ('22018', '[22018] [Microsoft][ODBC Driver 17 for SQL Server]Invalid character value for cast specification (0) (SQLExecute)')
I encountered pyodbc dataError -
sqlalchemy.exc.DataError: (pyodbc.DataError) ('22018', '[22018] [Microsoft][ODBC Driver 17 for SQL Server]Invalid character value for cast specification (0) (SQLExecute)')
while trying to insert into db table with…

Sharath Kallaje
- 21
- 1
- 4
1
vote
1 answer
Batch loading multiple CSV files which include Date into Oracle database Date
I am trying to load CSV files, which include a YYYY-MM-DD date format, to oracle database. But, always ended up with "DatabaseError: ORA-01861: literal does not match format string".
I think it needs a type of TO-DATE get invloved, but don'w know to…

SY Chun
- 13
- 2
1
vote
1 answer
Python SQL executemany statement doesn't work
I am trying to execute a delete statement that checks if the table has any SKU that exists in the SKU column of the dataframe. And if it does, it deletes the row.
supplier_name = input("Enter supplier name of the supplier you are updating: ")
df =…

loraine
- 39
- 1
- 7
1
vote
3 answers
Node.js + Oracledb + executeMany + batchErrors + Promise: does not execute all if one error
iam using BatchError with executeMany
if no errors.. everything is ok
but if one error or more .. it doesn't execute. it gives rowsAffected = error row number
my code:
const oracledb = require('oracledb');
async function post(req, res, next) {
…

MoodAttr
- 11
- 3
1
vote
1 answer
executemany of CLOB elements on cx_Oracle
I have a function that inserts a chunk of data into oracle database. I'm trying to achieve this by using executemany.
My function looks like this:
def InsertChunk(self):
try:
if len(self.list_dict_values) >= self.chunksize:
…

mohi666
- 6,842
- 9
- 45
- 51
1
vote
1 answer
Read CSV file into MySQL and use executemany instead of execute
I have a python script that reads a large (4GB!!!) CSV file into MySQL. It works as is, but is DOG slow. The CSV file has over 4 million rows. And it is taking forever to insert all the records into the database.
Could I get an example of how I…

bluethundr
- 1,005
- 17
- 68
- 141
1
vote
0 answers
UPDATE array execute many on python
I have this python code :
valuesupdatehdr=[(0, '2019-05-03 22:18:22', 'vq-01'), (0, '2019-05-03 22:18:24', 've-01'), (0, '2019-05-03 22:18:24', 'vb-01'), (0, '2019-05-03 22:18:25', 'bv-01'), (0, '2019-05-03 22:18:26', 'bb-01'), (0, '2019-05-03…
1
vote
0 answers
Trouble importing a .csv file to sqlite3 using python 3
I have tried this, and I'm having trouble getting it to work. I was originally having issues with utf decoding of the document, so I added the errors='ignore part. Now I'm at a pont where I'm having an sqlite3 syntax error. I have the same number of…

sr71shark
- 11
- 4
1
vote
3 answers
mixing placeholders, executemany, and table names
I can iterate through a python object with te following code, however I would like to be able to use placeholders for the schema and table name, normally I do this with {}.{} ad the .format() methods, but how do you combine the…

Spatial Digger
- 1,883
- 1
- 19
- 37
1
vote
1 answer
pyodbc bulk data import challenge using cursor.executemany( query, df.itertuples(index=False) )
I am reasonably new to python but have given this a serious bash to solve this elegantly.
The challenge: I am wanting to import market data from a pandas df into a sql table. There are some 7000 different stocks and each has some 4000-10000 End of…

Luthor
- 93
- 1
- 11