pymsql (1054, "Unknown column 'None' in 'call statement'")

Question:

I am trying to call stored procedure with pymsql but it looks like I am getting an error when one of the param is passed in as None. My stored proc is able to handle cases of Null but ofcourse not None. I was under the impression that pymysql automatically converts None to Null. Below is the code I am using.

_exec_statement = 'call kp_get_purchase_order(None,10,0)'
self.cursor.execute(_exec_statement)
return self.cursor.fetchall()

Error: pymysql.err.OperationalError: (1054, "Unknown column ‘None’ in
‘call statement’")

Is there a way to convert None to Null to pass into the cursor?

Asked By: Masterstack8080

||

Answers:

Use this instead.

_exec_statement = 'call kp_get_purchase_order(None,10,0)'.replace('None', 'null')
self.cursor.execute(_exec_statement)

was under the impression that pymysql automatically converts None to Null.

Yes. But only in a context where the None is visible, such as this:

_exec_statement = 'call kp_get_purchase_order(%s)'
args = (None, 10, 0)
self.cursor.execute(_exec_statement, *args)
Answered By: J_H
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.