Dynamic expression evaluation

From: "Philippe Lang" <philippe(dot)lang(at)attiksystem(dot)ch>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Dynamic expression evaluation
Date: 2003-11-10 14:41:07
Message-ID: 6C0CF58A187DA5479245E0830AF84F420AF75F@poweredge.attiksystem.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

Imagine we have the following kind of table, with two values (a and b), and a varchar (f) representing an expression.

----------------------------------
CREATE TABLE public.test
(
id serial NOT NULL,
a int4,
b int4,
f varchar(50),
CONSTRAINT id PRIMARY KEY (id)
) WITHOUT OIDS;

INSERT INTO public.test(a,b,f) VALUES(2,3,'a+b');
INSERT INTO public.test(a,b,f) VALUES(12,3,'a*b');
INSERT INTO public.test(a,b,f) VALUES(5,6,'a+2*b');
----------------------------------

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
------------------------------

Has anyone done anything like that already?

Thanks!

Philippe

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruno Wolff III 2003-11-10 14:51:17 Re: Problem Deleting Referenced records
Previous Message Tom Lane 2003-11-10 14:39:32 Re: Temp rows - is it possible?