K
K
Konstantin Malyarov2019-07-08 19:17:47
Python
Konstantin Malyarov, 2019-07-08 19:17:47

Empty SQL response of psycop2 query, but when querying via console it returns a string?

def show_all_orders():
    conn = try_connect()
    cursor = conn.cursor()
    try:
        rows = cursor.execute("SELECT * FROM orders")
        conn.commit()
        conn.close()
        cursor.close()
        print('Записи таблицы orders получены')
        return rows
    except Exception as e:
        print(f'Ошибка выборки записей orders: {str(e)}')
    print('Окончание запроса к таблице orders')

print(rows) returns None

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2019-07-08
@Konstantin18ko

fetchall

cur.execute("SELECT * FROM orders;")
rows = cur.fetchall()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question