Re: pattern matching with dates?

From: Susanne Ebrecht <susanne(at)2ndQuadrant(dot)com>
To: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: pattern matching with dates?
Date: 2011-01-07 12:39:47
Message-ID: 4D270993.302@2ndQuadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello Thomas,

On 05.01.2011 20:39, Good, Thomas wrote:
> select * from db_log where log_date LIKE '2011-01-%';

The lazy way would be something like this:
SELECT * from tab WHERE log_date::VARCHAR LIKE '2011-01-%';

The more proper way is:
SELECT * from tab WHERE EXTRACT(YEAR FROM log_date) = 2011 and
EXTRACT(MONTH FROM log_date) = 1;

Susanne

--
Susanne Ebrecht - 2ndQuadrant
PostgreSQL Development, 24x7 Support, Training and Services
www.2ndQuadrant.com

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message pasman pasmański 2011-01-07 14:15:03 Re: pattern matching with dates?
Previous Message Oliveiros d'Azevedo Cristina 2011-01-07 11:04:53 Re: return records with more than one occurrences