0

I have a function in PostgreSQL:

func(a integer, b integer)

When I call the function from Python:

"select * from func(%s,%s)"(a_1,b_1)

It works if a_1 and b_1 are integers. However there can be a case where b_1 is None. In this case I get this error message:

Exception: ERROR: column "none" does not exist LINE 1: ...func(38,None)

I know that None in Python is equivalent to PostgreSQL NULL, but in this case I don't know how to solve it.

2
  • 1
    Is it possible that a_1 or b_1 is anything other than an integer? Say, a string? Particularly a string such as '); DROP TABLE Something --' Commented Nov 29, 2016 at 7:36
  • @Kevin a_1 and b_1 data is received from integer fields in other DB. Commented Nov 29, 2016 at 9:07

1 Answer 1

1
"select * from func(%s,%s)" % (a_1, 'NULL' if b_1 == None else b_1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.