Error in crosstab using date_trunc

From: Jose Maria Terry Jimenez <jtj(at)tssystems(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Error in crosstab using date_trunc
Date: 2009-12-05 19:11:32
Message-ID: 4B1AB064.8040100@tssystems.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello all,

I'm trying to do a crosstab from data that row names are times.

These times are timestamps and i want to use they truncating to
minutes this works for me:

select distinct date_trunc('minute',"timestamp") as "timestamp" from
historico order by "timestamp";

Getting times "normalized" without seconds.

If i do a crosstab using that date_trunc function i get errors. If i do:

select *
from crosstab
(
'select date_trunc('minute',"timestamp") as "timestamp",remota,valor
from historico order by 1,2'
)
as
(anet timestamp without time zone,
re1 numeric,
re2 numeric,
re3 numeric
)
;

I get an error: (The part in Spanish means "Syntax error in or near")

PostgreSQL Error: ERROR: error de sintaxis en o cerca de «minute»
LINE 4: 'select date_trunc('minute',"timestamp") as "timestamp",remo...
^
I have tried
'select date_trunc('minute',"timestamp") as "timestamp",remota,valor
from historico order by 1,2'
'select (date_trunc('minute',"timestamp") ),remota,valor from historico
order by 1,2'
... changing quotes... but no luck.

Do anyone knows if i can't use that function or if i'm doing something bad?

Now i'm creating a temp table with timestamp "fixed" with date_trunc
(and works), but want skip that step:

create table temp as select (date_trunc('minute',timestamp)) as
"timestamp",remota,valor from historico;

And using temp for the crosstab.

Any help?, please.

Best,
Jose Maria

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Scanned with Copfilter Version 0.84beta3a (ProxSMTP 1.6)
AntiVirus: ClamAV 0.95.2/10114 - Fri Dec 4 23:54:13 2009
by Markus Madlener @ http://www.copfilter.org

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Filip Rembiałkowski 2009-12-05 20:10:43 Re: Array comparison & prefix search
Previous Message Daniel 2009-12-05 18:45:16 Re: Examples of using PQexecParams