我试图将一个包含许多列(未知数)的表取消透视到一个包含四列的表中。
我的查询如下所示:
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
这不起作用。我收到的错误消息是:
"ERROR: >>value<< has type numeric, but the expression is of type information_schema.sql_identifier"
"columns.column_name"
有没有机会通过转换为字符串或其他类似的东西来让它工作quote_ident()
?
我尝试的所有方法都不起作用。非常感谢你。