Oh great. Thanks a lot.
But now, I have another problem in this context. If I use text in the
SELECT statement (so, that the final output gives me the name of the
selected variables, plus the year and the value) than I get this
error message: ERROR: failed to find conversion function from
"unknown" to text
If I just use one of the SELECTs, it works fine. But as soon as I use
the UNION ALL and add the second SELECT, the error message appears.
What am I doing wrong? Thanks for any hints!
SELECT *
FROM (SELECT 'pop_density' AS name, d.year_start, d.value
FROM emissions_so2_total_rivm AS d
LEFT JOIN
countries AS c ON c.id = d.id_country
WHERE ((c.iso_2_code = 'CH') OR (c.iso_3_code =
'CH'))
ORDER BY d.year_start DESC
LIMIT 1) c1
UNION ALL
SELECT *
FROM (SELECT 'gdp' AS name, d.year_start, d.value
FROM emissions_so2_total_rivm AS d
LEFT JOIN
countries AS c ON c.id = d.id_country
WHERE ((c.iso_2_code = 'CH') OR (c.iso_3_code =
'CH'))
ORDER BY d.year_start DESC
LIMIT 1) c2
---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend