Re: UNION not working... why?

From: Stefan Schwarzer <stefan(dot)schwarzer(at)grid(dot)unep(dot)ch>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: UNION not working... why?
Date: 2007-12-14 06:48:07
Message-ID: 200443F5-5BCE-47CA-976A-2EFFCB8D60BD@grid.unep.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-12-14 06:54:01 Re: Need to find out which process is hitting hda
Previous Message Patrick TJ McPhee 2007-12-14 05:03:20 Re: timestamp with time zone