From: | "Stanislav Raskin" <sr(at)brainswell(dot)de> |
---|---|
To: | "'Tom Lane'" <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Understanding Aliases |
Date: | 2007-12-11 17:48:15 |
Message-ID: | E1J29DP-00046f-00@teena.zerebecki.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
> People frequently think that because ORDER BY can refer to the
> output-column aliases, other clauses should be able to do it too,
> but this is not so.
Thank you very much for clearing that one up.
Now I have a follow-up question. Let's assume that I want not only to
evaluate a subquery for the WHERE-statement, but also want to fetch the
result of this subquery. I think that this would be the correct way to do
so:
SELECT
t2.id,
(SELECT COUNT(id) FROM t4 WHERE t2_id = t2.id AND value=10)
AS t4_num
FROM
t2
WHERE
t2.active
AND (
(SELECT COUNT(id) FROM t4 WHERE t2_id = t2.id AND value=10) <= 3
)
Will the subquery be evaluated twice, or is postgres smart enough to somehow
cache the result from the first call of the subquery?
Kind Regards
Stanislav Raskin
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2007-12-11 17:59:52 | Re: how to create aggregate xml document in 8.3? |
Previous Message | Joshua D. Drake | 2007-12-11 17:47:27 | Re: Hijack! |