Last active
July 24, 2021 08:47
-
-
Save prithvihv/031d9ce001774b98a2508d6ac6fce47b to your computer and use it in GitHub Desktop.
(database locking for update) booking seat for x, database handling
This file contains 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 t_flight AS | |
SELECT * FROM generate_series(1, 200) AS id; | |
// concurrently we can call | |
SELECT * FROM t_flight LIMIT 2 FOR | |
UPDATE SKIP LOCKED; | |
// first time: 1, 2 | |
// second time: 3, 4 | |
// .... | |
// FOR UPDATE will have an impact on foreign keys | |
// if select (... table with foreign key reference b) for update is marked, then update on b will be blocked | |
// more on selecting the correct type of lock https://gist.github.com/prithvihv/dcf6f23999504f5103070d8635912b16 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment