Re: Select "todays" timestamps in an index friendly way

From: Mike Rylander <mrylander(at)gmail(dot)com>
To: lutz(dot)horn(at)posteo(dot)de
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Select "todays" timestamps in an index friendly way
Date: 2018-10-23 18:14:04
Message-ID: CAO8ar=mKGwR4Fdxg4NCKYOn=PhKWPuf3x+rtNBe6KAHL5+LrdA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Oct 23, 2018 at 5:38 AM Lutz Horn <lutz(dot)horn(at)posteo(dot)de> wrote:
>
> Hi,
>
> I am looking for a way to select all timestamps that are "today" in an
> index friendly way. This select should not depend on the concrete value
> of "today".
>

Per TFM, https://www.postgresql.org/docs/10/static/datatype-datetime.html
on table 8.13, you can use special input values:

SELECT * FROM t WHERE ts >= 'today'::timestamp AND ts < 'tomorrow'::timestamp;

HTH,

--
Mike Rylander
| Executive Director
| Equinox Open Library Initiative
| phone: 1-877-OPEN-ILS (673-6457)
| email: miker(at)equinoxinitiative(dot)org
| web: http://equinoxinitiative.org

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Hellmuth Vargas 2018-10-23 18:16:50 Re: Postgres 10, slave not catching up with master
Previous Message Francisco Olarte 2018-10-23 17:00:39 Re: Select "todays" timestamps in an index friendly way