Skip to content

Instantly share code, notes, and snippets.

@caub
Created January 13, 2018 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caub/533e7f1ea5909998bf360c176f94f6da to your computer and use it in GitHub Desktop.
Save caub/533e7f1ea5909998bf360c176f94f6da to your computer and use it in GitHub Desktop.
create table foo (
id bigserial primary key,
name text,
created date
);
insert into foo(name,created) values
('lol', '2018-01-09'),
('lol', '2018-01-08'),
('lol', '2018-01-08'),
('wow', '2018-01-07'),
('wow', '2018-01-09'),
('lol', '2018-01-09');
select * from foo order by name, id LIMIT 2;
select * from foo where id>2 OR name!='lol' order by name, id LIMIT 2;
select * from foo where id>6 OR name!='lol' order by name, id LIMIT 2;
@caub
Copy link
Author

caub commented Oct 27, 2018

so the idea is to add id at the end of your order by columns, and then for next page use the starting condtion id>lastId OR col!=lastColValue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment