Re: wrong query result

From: "Albe Laurenz" <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "josep porres *EXTERN*" <jmporres(at)gmail(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: wrong query result
Date: 2008-04-09 11:37:54
Message-ID: D960CB61B694CF459DCFB4B0128514C201FA5AA5@exadv11.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

josep porres wrote:
> select clau, lecact-lecant as m3, m3any, ta, tc, 3 as mesos, persones, true as clavegueram
> from fac_abonats
> where clau in (select clau from tmp_claus_prova)
> order by clau
>
> the thing is that the result of the query returns the same
> number of rows as the table fac_abonats (thousands).

[...]

> At the end I've realized that there is no column named
> 'clau'. It has another name.
> So the subselect query is wrong, if I execute it alone, an
> error appears
>
> ERROR: no existe la columna «clau»
> LINE 6: select clau from tmp_claus_prova
> ^
> ********** Error **********
>
> ERROR: no existe la columna «clau»
> Estado SQL:42703
> Caracter: 188
>
> The question is:
> Is it a normal behaviour? Because I think that if the query
> is wrong, wouldn't be better to raise an error?

Yes, this is normal behaviour.
The query is syntactically correct, it just doesn't do what you intended.

It will do the same as:

select clau, lecact-lecant as m3, m3any, ta, tc, 3 as mesos,
persones, true as clavegueram
from fac_abonats
where 42 in (select 42 from tmp_claus_prova)
order by clau

except probably less efficiently.

Yours,
Laurenz Albe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Albe Laurenz 2008-04-09 11:48:04 Re: select statement fails
Previous Message Dave Page 2008-04-09 11:27:18 Re: Debugging Pl/PgSQL functions with the debug contrib module