Re: Why lower's not accept an AS declaration ?

From: Hervé Piedvache <herve(at)elma(dot)fr>
To: Darko Prenosil <darko(dot)prenosil(at)finteh(dot)hr>, Postgresql General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Why lower's not accept an AS declaration ?
Date: 2003-08-18 16:59:44
Message-ID: 200308181859.44968.herve@elma.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

An to be more precise what I exactly want to do :

select
case when 'now' between t.begin and t.end then t.login else 'None' end as log
from my_table t
order by lower(log);

Is it an example more realistic for you to make an order by lower of something
as an alias ?

Regards,

Le Lundi 18 Août 2003 13:15, Darko Prenosil a écrit :
> On Monday 18 August 2003 13:04, Darko Prenosil wrote:
> > On Monday 18 August 2003 10:20, Hervé Piedvache wrote:
> > > Hi,
> > >
> > > May be my question is stupid ... but I'm a little suprised :
> > >
> > > SELECT id_letter as letter from my_table;
> > >
> > > letter
> > > -----
> > > B
> > > C
> > > a
> > > A
> > >
> > > SELECT id_letter as letter from my_table order by letter;
> > >
> > > letter
> > > -----
> > > A
> > > B
> > > C
> > > a
> > >
> > > SELECT id_letter as letter from my_table order by lower(letter);
> > >
> > > ERROR: Attribute "letter" not found
> >
> > Why did you change column name to "letter" in last query, and all the
> > other queries have "id_letter" as column name. What is table structure
> > exactly ? I assume that You don't have column with "letter" at all.
> >
> > Regards !
>
> OK, now I see exactly the mistake You are making:
>
> SELECT id_letter as letter from my_table order by lower(id_letter);
>
> would be correct query, because "letter" is only alias for result column,
> not column in "my_table". Sorry I didn't see it first time.
>
> Regards !
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
> joining column's datatypes do not match

--
Hervé Piedvache

Elma Ingénierie Informatique
6 rue du Faubourg Saint-Honoré
F-75008 - Paris - France
Pho. 33-144949901
Fax. 33-144949902

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rich Parker 2003-08-18 17:02:45 Re: New to list, quick question.
Previous Message Bruno Wolff III 2003-08-18 16:17:35 Re: Hour difference?