LoginSignup
3
3

More than 5 years have passed since last update.

postgressでグルーピングするときに忘れやすい関数

Last updated at Posted at 2014-04-08

日ごと、月ごとにグルーピングする

Action
  .select("DATE_TRUNC('day', created_at) AS created_at")
  .group("created_at")

グループングする際にUNIXTIMEで受け取る

Action
  .select("EXTRACT(EPOCH FROM DATE_TRUNC('day', created_at)) AS created_at")
  .group("created_at")

グループングする際にカンマ区切りのIDの配列を返すようにする

Action
  .select("STRING_AGG(id::text, ',') AS ids")
  .select("EXTRACT(EPOCH FROM DATE_TRUNC('day', created_at)) AS created_at")
  .group("created_at")

参考

3
3
1

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
3
3