Re: evaluating expressions stored in table

From: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "Little, Douglas *EXTERN*" <DOUGLAS(dot)LITTLE(at)orbitz(dot)com>, "PostgreSQL General (pgsql-general(at)postgresql(dot)org)" <pgsql-general(at)postgresql(dot)org>
Subject: Re: evaluating expressions stored in table
Date: 2012-12-19 08:59:53
Message-ID: A737B7A37273E048B164557ADEF4A58B0578AEBD@ntex2010i.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Douglas Little wrote:
> I need to evaluate an expression that I have stored in a table, and not sure how to force evaluation
> of a column value.

[...]
> The pass/fail query looks something like this
>
> Update testscore
> Set metricstatus = case when table_a.col_a = table_b.col_b then 'PASS' else 'FAIL' end
> ..
> Where testrunid=x
>
> I want to replace the table_a.col_a = table_b.col_b with the expression stored in the test table and
> evaluate.
>
> I'm thinking - it's dynamic sql, so I need to build the statement and then evaluate using a function.
>
> Anybody have any comments?

I would consider composing the statement in the application code:
SELECT the expression you need, compose the statement, send it
to the database.

If you need to do it on the database side, PL/pgSQL is your friend.
Since PostgreSQL 9.0 you can also use PL/pgSQL in the DO
SQL statement without having to define a function, but that will
probably not help if you need a return value.

Yours,
Laurenz Albe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Anjali Arora 2012-12-19 09:14:27 Vacuum analyze verbose output
Previous Message News Subsystem 2012-12-19 08:03:45