Re: Substring Problem

From: Sam Mason <sam(at)samason(dot)me(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Substring Problem
Date: 2008-05-13 13:56:27
Message-ID: 20080513135627.GA1657@frubble.xen.chris-lamb.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, May 13, 2008 at 03:26:57PM +0200, Stefan Schwarzer wrote:
> SELECT substring(date from 1 for 7) AS stryearmonth, COUNT(id) AS
> countofnumber FROM (SELECT * from downloads ) AS foo GROUP BY
> stryearmonth ORDER BY stryearmonth ASC

Another way of doing this is by using date_trunc, i.e.:

SELECT date_trunc('month',date) AS yearmonth...

I think it'll still realise it can use indexes (if they're appropriate)
that way.

Sam

In response to

Browse pgsql-general by date

  From Date Subject
Next Message ludwig 2008-05-13 13:56:38 Re: Substring Problem
Previous Message Gauthier, Dave 2008-05-13 13:56:03 PG -v- MySQL