Re: case, new column not found - Mailing list pgsql-sql

From Stephan Szabo
Subject Re: case, new column not found
Date
Msg-id Pine.BSF.4.21.0106211639320.5673-100000@megazone23.bigpanda.com
Whole thread Raw
In response to case, new column not found  (Martín Marqués <martin@bugs.unl.edu.ar>)
List pgsql-sql
On Thu, 21 Jun 2001, [iso-8859-1] Mart�n Marqu�s wrote:

> I'm trying somethings here and I get strange errors:
> 
> select *,(
>     (CASE WHEN titulo LIKE '%Matematica%' THEN 1 ELSE 0 END) + 
>     (CASE WHEN descripcion LIKE '%Matematica%' THEN 1 ELSE 0 END) +
>     (CASE WHEN incumbencia LIKE '%Matematica%' THEN 1 ELSE 0 END) ) 
> AS encontrados 
> FROM admin_view 
> WHERE admin_view.nivel=1 AND encontrados > 0;
> 
> ERROR:  Attribute 'encontrados' not found
> 
> Why is it? encontrados should be an attribute of type INT with the count of 
> the rows found.

IIRC, unless "encontrados" is both a pre-existing column of
admin_view and the name you're using in the select, it's only an item in a
select list.  It's not an attribute and since select list processing
happens after where clause processing (since you need to know which rows
to do it to -- imagine expensive computation in select list -- you
only want it to occur on returned rows) it isn't visible to the where
clause.




pgsql-sql by date:

Previous
From: Martín Marqués
Date:
Subject: case, new column not found
Next
From: Tom Lane
Date:
Subject: Re: case, new column not found