From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "Philippe Lang" <philippe(dot)lang(at)attiksystem(dot)ch> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Dynamic expression evaluation |
Date: | 2003-11-10 15:05:08 |
Message-ID: | 19478.1068476708@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
"Philippe Lang" <philippe(dot)lang(at)attiksystem(dot)ch> writes:
> Is there a simple way of doing "kind of" a
> SELECT *, EVAL(f) FROM public.test;
> ... and having f evaluated as an expression, so that we get back:
> ------------------------------
> id a b f eval
> ------------------------------
> 1 2 3 a+b 5
> 2 12 3 a*b 36
> 3 5 6 a+2*b 17
> ------------------------------
Not really. You can sort of approximate eval() with plpgsql's EXECUTE:
regression=# create or replace function eval(text) returns int as '
regression'# declare res record;
regression'# begin
regression'# for res in execute ''select '' || $1 || '' as result'' loop
regression'# return res.result;
regression'# end loop;
regression'# end' language plpgsql;
CREATE FUNCTION
regression=# select eval ('23+34');
eval
------
57
(1 row)
regression=#
but this has a problem with supporting more than one result type (hmm,
maybe you could fake that with 7.4's polymorphism?). And I don't see
any way at all for the function to have access to the other values in
the row, as your example presumes it would do.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Scott Chapman | 2003-11-10 16:09:29 | Re: SQL-question: returning the id of an insert querry |
Previous Message | My Deja | 2003-11-10 14:52:42 | Re: Internet based database |