Trying to get the next value in sequence from a postgres DB, with django
This code will work:
from django.db import connection, transaction
cursor = connection.cursor()
cursor.execute("select nextval('winner')")
result = cursor.fetchone()
full documentation about cursor
cursor.execute
always returns None.
To get the value from the SQL statement, you have to use cursor.fetchone()
(or fetchall()
).
See the documentation, although note that this doesn't actually have anything to do with Django, but is the standard Python SQL DB API.