38
38

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PostgreSQLで総件数とページングデータを同時に取得する

Posted at

RDBからデータを取得する際には

  • lmit/offsetをつけてデータ取得のSQLを発行する
  • それとは別に同じ条件のcount(*)を発行する

という2ステップが必要とずっと思っていたが、なんとそれを一発でやる方法があるということを今日知った。

select *, count(id) over() as full_count from table1 where id < 30 offset 0 limit 10;

なんなんだ**over()**って。。。(ググれ)
なかなかの衝撃。

38
38
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
38
38

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?