-
-
Save anonymous/a6654100d61a6a01c595 to your computer and use it in GitHub Desktop.
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
psql (9.4.1) | |
Type "help" for help. | |
test=# create table bug_or_feature (id bigserial not null primary key, created timestamp with time zone not null default now(), priority int not null, state text not null); | |
CREATE TABLE | |
test=# create index on bug_or_feature (priority DESC, created); | |
CREATE INDEX | |
test=# insert into bug_or_feature (priority, state) values (0, 'inactive'); | |
INSERT 0 1 | |
test=# insert into bug_or_feature (priority, state) values (0, 'inactive'); | |
INSERT 0 1 | |
test=# insert into bug_or_feature (priority, state) values (0, 'inactive'); | |
INSERT 0 1 | |
test=# select * from bug_or_feature; | |
id | created | priority | state | |
----+-------------------------------+----------+---------- | |
1 | 2015-03-01 20:13:49.070046+01 | 0 | inactive | |
2 | 2015-03-01 20:13:50.382009+01 | 0 | inactive | |
3 | 2015-03-01 20:13:58.077502+01 | 0 | inactive | |
(3 rows) | |
test=# update bug_or_feature set state = 'active' from (select id from bug_or_feature where state = 'inactive' order by priority desc, created limit 1 for update) job; | |
UPDATE 3 | |
test=# select * from bug_or_feature; | |
id | created | priority | state | |
----+-------------------------------+----------+-------- | |
1 | 2015-03-01 20:13:49.070046+01 | 0 | active | |
2 | 2015-03-01 20:13:50.382009+01 | 0 | active | |
3 | 2015-03-01 20:13:58.077502+01 | 0 | active | |
(3 rows) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment