Issue 311: Numpy types for inserting rows
Status:  New
Owner: ----
Reported by erlend.a...@gmail.com, Mar 12, 2013
What steps will reproduce the problem?
1. Use a numpy integer (numpy.int8,int16,...)
2. Insert as appropriate type in a db2 table


What is the expected output? What do you see instead?
It is impossible to insert using numpy types, or if inserted, the interpretation is wrong: the bits in the numpy types are interpreted wrong.


What version of the product are you using? On what operating system?
pyodbc 2.x and 3.x, on Linux 64-bit. Connecting to a RedHat 6.3 db2 9.7 server.

Please add support for numpy types in your library! It will greatly improve how it can be used for administering numerics inserted into dbs.
Aug 27, 2013
#3 randomiz...@gmail.com
It might be more a numpy problem rather than a pyodbc issue. The misbehavior is due to the fail of PyInt_Check or PyLong_Check on numpy.int32 and numpy.int64. After some searches, seems it is a well known issue but without a good solution yet.
Aug 27, 2013
#4 erlend.a...@gmail.com
To be honest, the python integers are the ones that are weird. This can easily be verified with sys.getsizeof. A numpy.int64 is a c integer using 64 bits of memory. python longs uses an arbitrary number of bits, depending on the magnitude of the integer. This issue may even cause problems in the database if you try to insert an integer which is bigger than the database type allows.

Example:
a=long(1000)
b=numpy.int64(a)

sys.getsizeof(a)
sys.getsizeof(b)

c=2**200
d=numpy.int64(c)

sys.getsizeof(c)