Re: Urgent help needed- alias name in update statement

From: venkatrao(dot)b(at)tcs(dot)com
To: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
Cc: Michael Wood <esiotrot(at)gmail(dot)com>, pgsql-novice(at)postgresql(dot)org, pgsql-novice-owner(at)postgresql(dot)org
Subject: Re: Urgent help needed- alias name in update statement
Date: 2010-03-10 04:20:23
Message-ID: OF2C8F7E0E.4212EB49-ON652576E2.00175A6B-652576E2.0017D70D@tcs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-novice

Friends, Thank you all for your prompt responses..

Thanks Michael, for correcting me..
Actually i also used to call it postgres earlier..but later somewhere in
net i found that it is postgre and not postgres..(may be i din' read that
time properly..)
anyways, now when i try to search that link , i could not find..
postgres sounds better than postgre...

see this...

http://www.postgresql.org/community/survey.33

Survey Results
The current results of our How do you pronounce 'PostgreSQL'? survey are:

Answer
Responses
Percentage
post-gres-q-l
2379
45.168%
post-gres
1611
30.587%
pahst-grey
24
0.456%
pg-sequel
50
0.949%
post-gree
350
6.645%
postgres-sequel
574
10.898%
p-g
49
0.930%
database
230
4.367%
Total
5267

From:
Josh Kupershmidt <schmiddy(at)gmail(dot)com>
To:
Michael Wood <esiotrot(at)gmail(dot)com>
Cc:
pgsql-novice(at)postgresql(dot)org
Date:
03/09/2010 11:32 PM
Subject:
Re: [NOVICE] Urgent help needed- alias name in update statement
Sent by:
pgsql-novice-owner(at)postgresql(dot)org

On Tue, Mar 9, 2010 at 10:42 AM, Michael Wood <esiotrot(at)gmail(dot)com> wrote:
[snip]
> I don't know why the above doesn't work. I've encountered something
> in the past which may be related:
>
> SELECT LOWER(SPLIT_PART(something, '^', 3)) AS blah
> FROM mytable
> WHERE something IS NOT NULL
> AND LOWER(SPLIT_PART(something, '^', 3)) <> ''
> AND other = 123;
>
> This works, but what I want to do is the following:
>
> SELECT LOWER(SPLIT_PART(something, '^', 3)) AS blah
> FROM mytable
> WHERE something IS NOT NULL
> AND blah <> ''
> AND other = 123;
>
> This does not work and I don't know why not.

This behavior is mandated by the SQL standard, I believe. I'm too lazy
to dig up the actual reference, but for instance
http://dev.mysql.com/doc/refman/5.0/en//problems-with-alias.html
claims:
Standard SQL disallows references to column aliases in a WHERE clause.
This restriction is imposed because when the WHERE clause is
evaluated,
the column value may not yet have been determined...

You could workaround by using a subquery like:

SELECT mysubq.blah FROM (
SELECT LOWER(SPLIT_PART(something, '^', 3)) AS blah
FROM mytable
WHERE something IS NOT NULL
AND other = 123
) AS mysubq
WHERE mysubq.blah <> '' ;

Josh

--
Sent via pgsql-novice mailing list (pgsql-novice(at)postgresql(dot)org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Sam Carleton 2010-03-10 04:59:04 Re: managing tablespaces like files?
Previous Message Bruce Momjian 2010-03-10 01:51:22 Re: log_statement and syslog severity

Browse pgsql-novice by date

  From Date Subject
Next Message Machiel Richards 2010-03-10 07:42:26 Slony vs Pgpool
Previous Message Josh Kupershmidt 2010-03-09 18:02:03 Re: Urgent help needed- alias name in update statement