Re: Select data for current week only

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Select data for current week only
Date: 2009-08-27 19:14:19
Message-ID: h76lu6$lqr$1@ger.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Sam Mason wrote on 27.08.2009 21:06:
>
> The OP leaves it somewhat open, but wouldn't date_trunc be better here?
>
> Otherwise you'll end up getting values for other years as well as the
> current one.

Good point, I didn't think of that :)

As an alternative, one could explicitely add the year into the where condition:

SELECT *
FROM the_table
WHERE extract(week from the_date_column) = extract(date from current_date)
AND extract(year from the_date_column) = extract(year from current_date);

but your solution is definitely more elegant ...

Thomas

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Kellerer 2009-08-27 19:18:57 Getting the column to a which a sequence belongs.
Previous Message Sam Mason 2009-08-27 19:10:51 Re: Select data for current week only