Search Postgresql Archives

Re: transpose time-series columnar data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.g.johnston@xxxxxxxxx) escribió:
On Tue, Aug 17, 2021 at 11:29 AM Edu Gargiulo <egargiulo@xxxxxxxxx> 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



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.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux