Search Postgresql Archives

Re: UNION not working... why?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux