It sounds like number is sometimes not an integer, such as an empty string.
You could handle this on the Python side by assigning number to None whenever int(number) is invalid:
try:
number = int(number)
except ValueError:
number = None
cur.execute("""SELECT name, number
FROM store
WHERE number=%s OR name =%s""",
(number, name))
cur.execute will handle None as NULL.
in GUI tkinter I would like to have an option to search my database only
by providing the name OR number, not providing both
If you want to search by number (first) or by name (second), but never both,
then use
import psycopg2
try:
cur.execute("""SELECT name, number
FROM store
WHERE number=%s""", (number, ))
except psycopg2.DataError:
cur.execute("""SELECT name, number
FROM store
WHERE name=%s""", (name, ))
invalid input syntax for integererror may occur if an empty string is passed as an argument instead of an integer. If that is the problem,int(number)will raise a ValueError on the Python side.