1
當我執行普通選擇時,會返回正確的結果,但是當我執行此選擇以進行數據庫正常運行時,它始終返回相同的第一個結果。我沒有檢查Postgres日誌,我發現select被執行。爲什麼psycopg2爲重複的SELECT返回相同的結果?
#!/usr/bin/python3 import psycopg2 from time import sleep conn = psycopg2.connect("dbname='MyDB' user='root' host='127.0.0.1' password='********'") cur = conn.cursor() def test(): e = 0 while e != 100: cur.execute("SELECT date_trunc('second', current_timestamp - pg_postmaster_start_time()) as uptime;") uptv = cur.fetchone() print(uptv) e += 1 sleep(0.1) test()
是'autocommit' off?.. –