Re: evaluating equation stored in a string - Mailing list pgsql-general

From Ludwig Isaac Lim
Subject Re: evaluating equation stored in a string
Date
Msg-id 20060426153313.84193.qmail@web33106.mail.mud.yahoo.com
Whole thread Raw
In response to evaluating equation stored in a string  ("SunWuKung" <Balazs.Klein@t-online.hu>)
List pgsql-general
Hi :

 How about creating a view that converts integer into
numeric?

create view <name> as
select <col1>::numeric as <col1>,
select <col2>::numeric as <col2>
...

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

ludwig lim


--- SunWuKung <Balazs.Klein@t-online.hu> 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

pgsql-general by date:

Previous
From: Chris Kratz
Date:
Subject: Re: Ordering of records in group by not possible
Next
From: Alban Hertroys
Date:
Subject: Re: Ordering of records in group by not possible