From: rob stone <floriparob@gmail.com>
To: hmidi slim <hmidi.slim2@gmail.com>
To: pgsql-general@postgresql.org
Subject: Re: Extract dates of a given day
Date: Fri, 06 Apr 2018 22:21:01 +1000
Message-ID: <1523017261.3576.6.camel@gmail.com> (raw)
In-Reply-To: <CAMsqVxtCJzovZrXd17_cC-BoYC+JPGm38rmCH12o+fhrYX4bzg@mail.gmail.com>
References: <CAMsqVxtCJzovZrXd17_cC-BoYC+JPGm38rmCH12o+fhrYX4bzg@mail.gmail.com>
Hello,
On Fri, 2018-04-06 at 11:32 +0100, hmidi slim wrote:
> Hi,
> I have a table availability: id (integer), product varchar(255),
> period (daterange)
> I want to extract dates from a given period matching a given day.
> E.g: for the period from 01/04/2018 - 30/04/2018 and for day =
> Monday I want to get
> 02/04/2018
> 09/04/2018
> 16/04/2018
> 23/04/2018
> 30/04/2018
>
> I want to make a query such as (the query doesn't work ) but I want
> to extract dates from daterange type:
> select * from availability
> where period @> '[2018-04-02, 2018-04-20]'
> and extract(dow from period_date) = 1
>
> How can I extract dates from daterange?
There is no column called "period_date".
You might try:-
SELECT id, product, period
FROM availability
WHERE period @> '[2018-04-02, 2018-04-09, 2018-04-16, 2018-04-23, 2018-
04-30)'::daterange
ORDER BY product;
Not tested. Not sure exactly what your application needs.
HTH,
Rob
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: floriparob@gmail.com, hmidi.slim2@gmail.com
Subject: Re: Extract dates of a given day
In-Reply-To: <1523017261.3576.6.camel@gmail.com>
References: <CAMsqVxtCJzovZrXd17_cC-BoYC+JPGm38rmCH12o+fhrYX4bzg@mail.gmail.com> <1523017261.3576.6.camel@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox