Postgresql query between date ranges

前端 未结 5 1612
轻奢々
轻奢々 2020-12-04 07:51

I am trying to query my postgresql db to return results where a date is in certain month and year. In other words I would like all the values for a month-year.

The

5条回答
  •  悲哀的现实
    2020-12-04 08:51

    From PostreSQL 9.2 Range Types are supported. So you can write this like:

    SELECT user_id
    FROM user_logs
    WHERE '[2014-02-01, 2014-03-01]'::daterange @> login_date
    

    this should be more efficient than the string comparison

提交回复
热议问题