Passing a timestamp as a parameter

93 views
Skip to first unread message

TDK

unread,
Aug 20, 2020, 10:16:51 PM8/20/20
to ibm_db
Hi,

in my code I'm passing 3rd of the parameters has timestamp value, type str!
-------------------------------------------------------------------------------------------------------------
sql_insert = """ 
                            INSERT INTO TABLE
                            (COL1,  COL2  ,  COL3  ,  COL4  )
                            VALUES (?, ?, ?, ?)
                        """     

            params = value1,  value2  ,  value3  , value4

            cursor_insert = self.__conn.cursor()
        
            cursor_insert.execute(operation=sql_insert, parameters= params)
-------------------------------------------------------------------------------------------------------------  

After runing the program I get this error:

[DataError("Exception('Statement Execute Failed: [IBM][CLI Driver][DB2/AIX64] SQL0180N  The syntax of the string representation of a datetime value is incorrect.  SQLSTATE=22007\\r SQLCODE=-180')")]

In DB2 database that 3rd column is defined as TIMESTAMP but there isnt timestamp type in Python? 
Can somebody help?

erik.lenna...@gmail.com

unread,
Aug 21, 2020, 12:34:59 AM8/21/20
to ibm...@googlegroups.com
On Thu, 2020-08-20 at 08:33 -0700, TDK wrote:

[...]


After runing the program I get this error:
[DataError("Exception('Statement Execute Failed: [IBM][CLI Driver][DB2/AIX64] SQL0180N  The syntax of the string representation of a datetime value is incorrect.  SQLSTATE=22007\\r SQLCODE=-180')")]

In DB2 database that 3rd column is defined as TIMESTAMP but there isnt timestamp type in Python? 
Can somebody help?

Try using a string, formatted as an iso-timestamp:

'2020-08-21-05.51.48.886035' 


/Lennart
 

TDK

unread,
Aug 21, 2020, 3:50:13 AM8/21/20
to ibm_db
OK I'm blind. I've checked this 5 times and didn't see that TS format  was "%d-%m-%Y %H:%M:%S.%f"  instead of "%Y-%m-%d %H:%M:%S.%f". 
Now it works!
Tnx Lennart
Reply all
Reply to author
Forward
0 new messages