0

So say i want to query some data form a postgresql table.

The table contains timeseries data and has the columns curve_id, datetime, value, edit_datetime.

Now when querying from excel I just write the simple:

SELECT * 
FROM Table 
WHERE curve_id IN ('Var1', 'Var2' ...) 

That returns one long list.

curve_id, datetime, value, edit_datetime

(VAR1, 2021-10-07 00:00:00, 17,2021-10-07 01:51:05  ),
(VAR2, 2021-10-07 00:01:00, 19,2021-10-07 02:43:05  ),
(VAR1, 2021-10-07 00:01:00, 18,2021-10-07 01:51:05  ),
(VAR2, 2021-10-07 00:01:30, 20,2021-10-07 02:55:05  )

But say I want the output table in a format where each variable gets its own column. How do I proceed to do that in the SQL code and not just do a fix in Excel?

Something like

Datetime, VAR2_value, VAR2_value

(2021-10-07 00:00:00, 17, *),
(2021-10-07 00:01:00, 18, 19),
(2021-10-07 00:01:30, *, 20)
a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843
  • Have you fixed set of variables? If yes, then you need to use pivot (crosstab); if not, then no good solution. Read here too: https://stackoverflow.com/questions/34502696/postgres-crosstab-dynamic-number-of-columns – Arvo Oct 07 '21 at 06:41

0 Answers0