Re: [GENERAL] evaluating equation stored in a string

2006-04-26 Thread Alban Hertroys

SunWuKung wrote:

However I have a problem with this cast. I don't know how to handle
brackets in the equation, since

SELECT 35/124 ::numeric
--0.28

while

SELECT (35/124) ::numeric
-- 0


The brackets aren't your problem, your numbers aren't as accurate as the 
result you require. An eval() function would give the same results. 
You'll want this instead:


SQL> select (35.0/124.0)::numeric;
numeric

 0.28225806451612903226


Regards,
--
Alban Hertroys
[EMAIL PROTECTED]

magproductions b.v.

T: ++31(0)534346874
F: ++31(0)534346876
M:
I: www.magproductions.nl
A: Postbus 416
   7500 AK Enschede

// Integrate Your World //

---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


Re: [GENERAL] evaluating equation stored in a string

2006-04-26 Thread Ludwig Isaac Lim
Hi :

 How about creating a view that converts integer into
numeric?

create view  as
select ::numeric as ,
select ::numeric as 
...

and then query the view instead. This way your formula
doesn't need to use cast anymore.

ludwig lim


--- SunWuKung <[EMAIL PROTECTED]> wrote:

> I have equations stored in strings and I would need to
> evaluate them in
> pgsql - get the result.
> Maybe there is an eval() function but I couldn't find it.
> 
> The only way I found was to use something like this:
> 
> calcstring_arg:= 'SELECT ' || calcstring_arg || '
> ::numeric AS
> outparam';
> FOR tmp IN EXECUTE calcstring_arg LOOP END LOOP;
> RETURN tmp.outparam;
> 
> However I have a problem with this cast. I don't know how
> to handle
> brackets in the equation, since
> 
> SELECT 35/124 ::numeric
> --0.28
> 
> while
> 
> SELECT (35/124) ::numeric
> -- 0
> 
> so I should do something like
> 
> SELECT (35::numeric/124::numeric)
> --0.28
> 
> But than I would need to start to look inside the string
> and do
> manipulation to it that I would like to avoid. How could
> I evaluate
> these strings independently from whether there are
> brackets in them or
> not?
> 
> Thanks for the help.
> Balázs
> 
> 
> ---(end of
> broadcast)---
> TIP 3: Have you checked our extensive FAQ?
> 
>http://www.postgresql.org/docs/faq
> 


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


[GENERAL] evaluating equation stored in a string

2006-04-26 Thread SunWuKung
I have equations stored in strings and I would need to evaluate them in
pgsql - get the result.
Maybe there is an eval() function but I couldn't find it.

The only way I found was to use something like this:

calcstring_arg:= 'SELECT ' || calcstring_arg || ' ::numeric AS
outparam';
FOR tmp IN EXECUTE calcstring_arg LOOP END LOOP;
RETURN tmp.outparam;

However I have a problem with this cast. I don't know how to handle
brackets in the equation, since

SELECT 35/124 ::numeric
--0.28

while

SELECT (35/124) ::numeric
-- 0

so I should do something like

SELECT (35::numeric/124::numeric)
--0.28

But than I would need to start to look inside the string and do
manipulation to it that I would like to avoid. How could I evaluate
these strings independently from whether there are brackets in them or
not?

Thanks for the help.
Balázs


---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq