Answer the question
In order to leave comments, you need to log in
Why don't SELECT queries work in Psycopg2?
Library psycopg2-2.7.4
import psycopg2
class Database:
def __init__(self, database):
self.conn = psycopg2.connect(database)
self.cursor = self.conn.cursor()
def put_balance(self, bal, chat_id):
with self.conn:
self.cursor.execute('UPDATE profile SET points = %s WHERE chat_id = %s', (bal, chat_id))
def get_balance(self, chat_id):
with self.conn:
return self.cursor.execute('SELECT points FROM profile WHERE chat_id = %s;', (chat_id,))
Answer the question
In order to leave comments, you need to log in
initd.org/psycopg/docs/usage.html
# Query the database and obtain data as Python objects
>>> cur.execute("SELECT * FROM test;")
>>> cur.fetchone()
(1, 100, "abc'def")
# Make the changes to the database persistent
>>> conn.commit()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question