Created
April 29, 2025 10:59
-
-
Save CHERTS/d8badf2e1ca8de245bc607bc22611540 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE test ( | |
id BIGINT GENERATED ALWAYS AS IDENTITY NOT NULL PRIMARY KEY, | |
data_field VARCHAR(255) NOT NULL | |
); | |
INSERT INTO test(data_field) SELECT(i::text) FROM generate_series(1,10000) as t(i); | |
-- repeat several times | |
WITH candidate_rows AS ( | |
SELECT id | |
FROM test | |
WHERE data_field <> 'updated' | |
LIMIT 1200 | |
FOR UPDATE NOWAIT | |
), update_rows AS ( | |
UPDATE test | |
SET data_field = 'updated' | |
FROM candidate_rows | |
WHERE candidate_rows.id = test.id | |
RETURNING test.id | |
) | |
SELECT count(1) FROM update_rows; | |
DROP TABLE test; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment