0
I’m having trouble understanding why the code below only returns result when executed in the terminal.
I intend to return hash of the last id entered in the database
connection = psycopg2.connect("dbname=vone")
cursor = connection.cursor()
SQL = """
SELECT hash
FROM pos_order
WHERE id = ( SELECT max(id) FROM pos_order );"""
cursor.execute(SQL)
hash = cursor.fetchone()[0]
When executing the code within a function, the method cursor.fetchone()
returns None.
Ask the question SQL
CREATE TABLE pos_order
and a data sample (text format) for testing.– Augusto Vasques