Repository navigation
Description
- What versions are you using?
oracledb.version:
Linux-3.10.0-1160.105.1.el7.x86_64-x86_64-with-glibc2.17
True
3.9.18
-
Is it an error or a hang or a crash?
-
What error(s) or behavior you are seeing?
Hallo when i try executmany into a table i got the following error:
DPY-3013 unsupported Python type int for database type DB_TYPE_VARCHAR
I try to insert values into a table.
first i create e Table via:
CREATE TABLE (Name1 NUMBER(10), Name2 NUMBER(2))
everything works fine
after this i try to insert values in batches/chunks (each 10000)
The first iteration is fine with execute many
INSERT INTO (Name1, Name2) values (values for Name1, values for Name2)
Important: all values for Column Name2 are None in the first batch!
In the next batch/chunk:
all values for Column Name2 are None except the last 200 (from 9800-10000) are Integers between 0-6
in the executemany statement i ve got the above error.
What I am doing wrong?
Thanx Sven
python skript
import numpy as np
import oracledb
oracledb.init_oracle_client()
con = oracledb.connect(user=env.USER_MD_WSP,
password=env.PWD,
dsn=env.DNS)
cur = con.cursor()
sql = "CREATE TABLE TB_BUG (NAME1 NUMBER(10), NAME2 NUMBER(2))"
cur.execute(sql)
con.commit()
batch1 = [(n, None) for n in range(10000)]
sql = "insert into TB_BUG (NAME1, NAME2) values (:1, :2)"
cur.executemany(sql, batch1, batcherrors=True)
con.commit()
batch2 = [(n, None) for n in range(9000)]
batch2_1 = [(n, np.random.randint(0, 6)) for n in range(1000)]
batch2_all = batch2 + batch2_1
sql = "insert into TB_BUG (NAME1, NAME2) values (:1, :2)"
cur.executemany(sql, batch2_all, batcherrors=True)
con.commit()
Activity
anthony-tuininga commentedon Feb 12, 2024
This is not a bug but expected behavior. If you call executemany() and all of the values are NULL, then the driver assumes that the value is of type DB_TYPE_VARCHAR with length 1. When you call it again with some values that are integers the driver complains because you can't assign integers to DB_TYPE_VARCHAR. If you have this situation you need to call cursor.setinputsizes() like the following:
That will tell the driver that you intend to store integers (numbers) and the value null (None) can still be assigned.
sfanghaenel commentedon Feb 13, 2024
Thanx for your Answer.
This behavior is a little bit strange because i define the Datatype explicit as a Number(2) in the create Table statement.
Some times i have a big Table with many rows and columns (20.000.000 x 200) with different Datatypes. Often are Null values in the first 1.000.00 rows in some columns. Than i run in this error. How can i fix this error?
Do i have to declare the Datytypes before:
e.G. Table with 4 Columns with Datatypes:
Varchar2(20), Number(10), Number(2), Varchar2(5)
cur.setinputsizes(?,?,?,?)
Thanx Sven
anthony-tuininga commentedon Feb 13, 2024
When performing an insert there is no way for the driver to know anything about the data unless you supply that information! If the data types are not known by your application and you don't mind incurring a round trip to the database to figure that out you can perform a query against the table you are inserting into and look at the metadata that is returned in
Cursor.description, then make a call toCursor.setinputsizes()as needed. This is necessary when you have so many null values as there is no way to differentiate betweenNoneintended for a NUMBER column andNoneintended for a DATE column andNoneintended for a VARCHAR2 column!HayDegha0917 commentedon Feb 22, 2024
Is the driver attempting to insert
Nonevalues as VACHAR2(1)? My naive assumption is thatNoneis the equivalent ofNULL, which can be inserted into any non-null column.anthony-tuininga commentedon Feb 25, 2024
Yes,
Noneis the equivalent ofNULLwhich can be inserted into any column. The problem is that if you supply aNonevalue there is no way to know the type of that data -- so the driver simply assumesVARCHAR2(1). You can avoid that assumption by usingCursor.setinputsizes().anthony-tuininga commentedon Mar 11, 2024
I will close this under the assumption that your question has been answered. If not, please feel free to re-open!
avmcohen commentedon Feb 6, 2025
Just note that the same binding works fine in cx_Oracle. Just in oracledb it is required
anthony-tuininga commentedon Feb 6, 2025
That seems highly unlikely. Please open a new issue with a test case demonstrating the issue!
anthony-tuininga commentedon Dec 16, 2025
Someone else reported this issue and provided a test case that demonstrated the problem. I will get this corrected!
Fixed bug when calling Cursor.executemany() with all of the values in at
anthony-tuininga commentedon Dec 23, 2025
I have pushed a patch that should correct this issue and have initated a build from which you can download pre-built development wheels once it completes. You can also build from source if you prefer. If you can test your scenario and confirm the patch works as expected, that would be appreciated!
Fixed bug when calling Cursor.executemany() with all of the values in at
anthony-tuininga commentedon Jan 23, 2026
I have initiated a new build on the
v3.4.xbranch in preparation for the release of python-oracledb 3.4.2.anthony-tuininga commentedon Jan 28, 2026
This was included in python-oracledb 3.4.2 which was just released.
qbabor4 commentedon Jan 29, 2026
I can confirm that version 3.4.2 no longer produces
oracledb.exceptions.NotSupportedError: DPY-3013: unsupported Python type datetime for database type DB_TYPE_VARCHAR
when using cursor.executemany() .
setinputsizes() was not necessary.
talibtahir commentedon Jan 31, 2026
I facing same issue
anthony-tuininga commentedon Jan 31, 2026
Upgrade to python-oracledb 3.4.2? Or if you are still facing it with that version, open a new issue providing details!
chore(oracle): upgrade oracledb for DPY-3013 issue