Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Novice > Re: Expression ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 3 Topic 3082 of 3323
Post > Topic >>

Re: Expression on an Expression alias

by tgl@[EMAIL PROTECTED] (Tom Lane) Apr 18, 2008 at 04:31 PM

"Mike Ellsworth" <younicycle@[EMAIL PROTECTED]
> writes:
> The *effect* I'd like is to 'reuse' FV1, ~

> SELECT
> fv_test.acct_val AS acct_val,
> fv_test.time AS time,
> fv_test.i AS interest_rate,
> FV(fv_test.acct_val,fv_test.i,fv_test.time) AS FV1,
> FV1 *2 AS FV2,
> FV1 *3 AS FV3
> FROM    "hrcommu"."fv_test"

This is flat out invalid according to the SQL spec.  The SELECT
expressions are notionally computed in parallel and so can't refer
to each other.

You can do something vaguely like what you want with nested
SELECTs:

SELECT
FV1,
FV1 *2 AS FV2,
FV1 *3 AS FV3
FROM
(SELECT
   FV(fv_test.acct_val,fv_test.i,fv_test.time) AS FV1
 FROM    "hrcommu"."fv_test"
) ss;

although how much advantage there is is debatable.
(In particular, this is very likely to still call fv()
three times per row.)

			regards, tom lane

-- 
Sent via pgsql-novice mailing list (pgsql-novice@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice
 




 3 Posts in Topic:
Expression on an Expression alias
younicycle@[EMAIL PROTECT  2008-04-18 16:21:42 
Re: Expression on an Expression alias
tgl@[EMAIL PROTECTED] (T  2008-04-18 16:31:57 
Re: Expression on an Expression alias
younicycle@[EMAIL PROTECT  2008-04-18 16:42:18 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Dec 5 4:50:24 CST 2008.