插入新元素時“LIMIT OFFSET”是否穩定? (Is 'LIMIT OFFSET' stable when new element inserted?)


問題描述

插入新元素時“LIMIT OFFSET”是否穩定? (Is 'LIMIT OFFSET' stable when new element inserted?)

讓我們考慮一個場景。

一個表有1000行。

我查詢了LIMIT 100的行。

查詢後,一些插入表中的行。

然後,我再次查詢,使用 LIMIT 100 和 OFFSET 100。

我希望結果與第一次查詢無關。

我想在第一次查詢後得到結果。

我該怎麼做?請幫忙。


參考解法

方法 1:

The SQL standard makes no promise regarding the natural ordering of rows in a table ‑ new rows may be inserted at the end of a table or anywhere in the middle. Depending on where your dbms inserted the rows, which will likely depend on what rows were previously deleted, your second query could easily select rows already selected in the first query, or skip some rows between queries.

The only way I can think to do what you want reliably is to select the entire table into a temporary table, or a cursor, and then read records 100 at a time from that second record set.

You could also perform all your queries within a single serializable transaction (which would hide any inserts or deletes performed by other users for the duration of your transaction) but even that would not be a foolproof solution.

(by Beom Soo JoungDarwin von Corax)

參考文件

  1. Is 'LIMIT OFFSET' stable when new element inserted? (CC BY‑SA 2.5/3.0/4.0)

#offset #SQL #limit






相關問題

ASM 使用代碼查找偏移量 (ASM find offset with code)

沒有在偏移量 0 處映射 Win32 便攜式可執行文件的可能原因是什麼? (What are possible reasons for not mapping Win32 Portable Executable images at offset 0?)

Адлюстраванне тоста з зададзеным зрушэннем (Displaying toast at a given offset)

c - 刪除前 4 個字節的數據 (c - remove first 4 bytes of data)

PCM 樣本位置 [字節偏移] 在 flac (PCM sample position [byte offset] in flac)

到達 (window).scroll 上的中間元素 (Reach middle element on (window).scroll)

插入新元素時“LIMIT OFFSET”是否穩定? (Is 'LIMIT OFFSET' stable when new element inserted?)

如何從包含 Oracle 中時區偏移的日期/時間字符串中獲取 UTC 日期/時間 (How to get UTC date/time from a date/time string that contains timezone offset in Oracle)

嚴重性:警告消息:非法字符串偏移 'id' MY OWN PROJECT (Severity: Warning Message: Illegal string offset 'id' MY OWN PROJECT)

jquery 獲取和設置文檔偏移量(或位置?) (jquery get and set document offset (or position?))

在地址位移內還是在地址位移外相乘更有效? (Is it more efficient to multiply within the address displacement or outside it?)

如何在裝配中進行十六進制偏移計算 (how to do hex offset calculation in assembly)







留言討論