Re: Select data for current week only - Mailing list pgsql-general

From Thomas Kellerer
Subject Re: Select data for current week only
Date
Msg-id h76lu6$lqr$1@ger.gmane.org
Whole thread Raw
In response to Re: Select data for current week only  (Sam Mason <sam@samason.me.uk>)
List 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



pgsql-general by date:

Previous
From: Sam Mason
Date:
Subject: Re: Select data for current week only
Next
From: Thomas Kellerer
Date:
Subject: Getting the column to a which a sequence belongs.