Skip site navigation (1) Skip section navigation (2)

Expression on an Expression alias

From: "Mike Ellsworth" <younicycle(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Expression on an Expression alias
Date: 2008-04-18 20:21:42
Message-ID: 219951fd0804181321k3d756da2k8a0198fe73abcfce@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
I'm wondering if there is a way to write an expression on an
expression alias... or 'build on' an existing expression alias.
I am slowly converting old Filemaker work to PG and the below would be helpful.
My old Filemaker allows something similar to var 2 below.

This is an example ( a little feeble) where FV is a function
the first one works, but can get lengthy if I start to nest variations.

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,
FV(fv_test.acct_val,fv_test.i,fv_test.time) *2 AS FV2,
FV(fv_test.acct_val,fv_test.i,fv_test.time) *3 AS FV3
FROM    "hrcommu"."fv_test"

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"

Any suggested reading, would be read.
Thanks

Responses

pgsql-novice by date

Next:From: Tom LaneDate: 2008-04-18 20:31:57
Subject: Re: Expression on an Expression alias
Previous:From: Mija LeeDate: 2008-04-18 19:57:36
Subject: finding information about tables and databases

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group