简体   繁体   中英

cursor.fetchmany vs DECLARE BINARY CURSOR and FETCH

I am not sure which is the most effective or the disadvantages/advantages of each approach or whether they are technically the same thing ?

That is

cursor.execute("DECLARE super_cursor BINARY CURSOR FOR SELECT names FROM myTable")

while True:
cursor.execute("FETCH 1000 FROM super_cursor")
rows = cursor.fetchall()

as expressed in the answer given by alecxe python postgres can I fetchall() 1 million rows?

In comparison to:

while True:
    results = cursor.fetchmany(1000)
    if not results:
        break
    for result in results:
        yield result

Should one use fetchmany as specified in psycopg2 or DECLARE BINARY.

I Have assumed that fetchmany and DECLARE BINARY both setup a temporary table on the database server side... The client side is an Apache server.

The website I am working with does calculations on user input to that of data in the database... Hence needs to load large amounts of data for pattern matching.

Thank you.

I have 1B records in my DB, DECLARE BINARY CURSOR solution can imediately iterate over the table whereas fetchmany has a very big delay to start working which I assume is because of preprocessing and loading data to the memory. So in my case BINARY CURSOR is more efficient.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM