Re: transpose time-series columnar data

From: Cachique <cachique(at)gmail(dot)com>
To: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: transpose time-series columnar data
Date: 2021-08-17 22:31:38
Message-ID: CAEfeRhVcEa=UtLtGE1TAF14DTWLSsqya1Oo_r4qptJHCDUPf2A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

As suggested by David I would use Tablefunc.

This query should work.

select * from crosstab (
'select timestamp, name, value from originaltable',
'select distinct name from originaltable order by name'
)
as transposedtable (timestamp varchar, name1 varchar, name2 varchar, name3
varchar)

Regards,
Walter

El mar, 17 de ago. de 2021 a la(s) 14:42, David G. Johnston (
david(dot)g(dot)johnston(at)gmail(dot)com) escribió:

> On Tue, Aug 17, 2021 at 11:29 AM Edu Gargiulo <egargiulo(at)gmail(dot)com> wrote:
>
>>
>> I need to transpose and return one row for a single timestamp and one
>> column for every name (fixed number of names), something like this
>>
>>
> https://www.postgresql.org/docs/current/tablefunc.html
>
> or
>
> select ..., max(value) filter (where name = 'name1') as name1, max(value)
> filter (where name = 'name2') as name2, etc from tbl group by ...
>
> David J.
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message A Z 2021-08-18 02:49:56 Serious Assistance with PostgreSQL True Infinite Arbitrary Precision Maths.
Previous Message Ron 2021-08-17 20:15:02 Re: Join for the parent table will not leverage the index scan