I need to run a query in PostgreSQL to first update a record and then return it. Here's the query:
WITH x AS (
SELECT "ID" FROM JOB WHERE "STATE" = 1 LIMIT 1
)
UPDATE JOB y SET "STATE" = 2 FROM x WHERE x."ID" = y."ID"
RETURNING y.*
It works fine in PostgreSQL server itself. However, running it in Python with pyodbc does not work.
cursor.execute(query)
results = cursor.fetchall()
It says "No results. Previous SQL was not a query."