Jiří Němec wrote:
> Hello all,
>
> I wrote a function which counts price of product from retail price and
> discount. It works. But I need to count price with tax of same
> product. The best way is to use counted price and add only a tax. I
> would like to do by this way:
>
> SELECT count_price(retail, discount) AS price, count_price_tax(price,
> tax) FROM foo.
>
> But PostgreSQL reports that "price" column doesn't exist. It doesn't
> exist, but is counted by first calling "count_price()" function.
>
> Is there some way how I shouldn't count these prices twice and use
> just counted price?
It's not quite clear to me what count_price and count_price_tax are
supposed to do. Does count_price_tax return the equivalent of
price*(1.0+tax) (or maybe price*tax)? If so, one way to do it is to use
a sub-query like this:
SELECT price, count_price_tax(price, tax) FROM (SELECT
count_price(retail, discount) AS price, tax FROM foo) AS bar;
--
--------------------------------------------------------------------
Aaron Bingham
Application Developer
Cenix BioScience GmbH
--------------------------------------------------------------------