Re: .TO_CHAR problem - Mailing list pgsql-general

From Karel Zak
Subject Re: .TO_CHAR problem
Date
Msg-id Pine.LNX.3.96.1010219092323.15975A-100000@ara.zf.jcu.cz
Whole thread Raw
In response to .TO_CHAR problem  (Guillaume Lémery <glemery@comclick.com>)
List pgsql-general
On Thu, 15 Feb 2001, Guillaume [ISO-8859-1] Lémery wrote:

> Hi all,
>
> I want to have some stats from my data grouped by 2hours periodes.
>
> Here is the query :
>
> SELECT TO_DATE(TO_CHAR    (date_clic,'DD-MM-YYYY ')
>         ||     (TO_CHAR(
>                 TO_NUMBER(
>                     TO_CHAR(date_clic,'hh24')
>                 , 99)
>                      - mod(
>                          TO_NUMBER(
>                              TO_CHAR(date_clic,'hh24')
>                          , 99)
>                      ,2)
>                  , 'hh24')
>                  )
>              ||':00','DD-MM-YYYY HH24:MI') AS date_debut
> FROM clic_campagne;
>
> But I only get the date whithout the hours and the minute, how can I get
> them ?

 As you say "..get the date...", hours+minutes+ contains timestamp.

 You must call SELECT TO_TIMESTAMP(...) instead TO_DATE(...).

 BTW, I not sure if your TO_NUMBER() is needful, less expensive will
probably TO_CHAR(date_clic,'hh24')::int.

                Karel





pgsql-general by date:

Previous
From: "Mark Cowlishaw"
Date:
Subject: not using table aliases in where clause slow-down?
Next
From: "Richard Huxton"
Date:
Subject: Re: Default values?