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.johns...@gmail.com) escribió:

> On Tue, Aug 17, 2021 at 11:29 AM Edu Gargiulo <egargi...@gmail.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.
>
>

Reply via email to