i tried to unpivot a table with many columns (unknown number) into a table with four columns.
My query looks like this:
INSERT INTO measurement (timestamp, sensor, value)
SELECT d."Timestamp",
( SELECT s.id FROM sensor s WHERE s.name = columns.column_name),
( SELECT columns.column_name from sensor_list where "Timestamp" = d."Timestamp")
FROM sensor_list d,
(SELECT column_name FROM information_schema.columns WHERE table_name = 'sensor_list' AND column_name <> 'Timestamp' ORDER BY ordinal_position) columns
This doesnt work. The Errormessage i receive is:
"ERROR: >>value<< has type numeric, but the expression is of type information_schema.sql_identifier"
Is there any chance to get it work by converting "columns.column_name" to string or something else like with quote_ident() ?
All i tried did not work. Thank you very much.