Re: Obtain boolean value of expression in PLPGSQL

From: Richard Huxton <dev(at)archonet(dot)com>
To: Max Speransky <mx(at)lucky(dot)net>, pgsql-general(at)postgresql(dot)org
Subject: Re: Obtain boolean value of expression in PLPGSQL
Date: 2003-11-04 11:12:17
Message-ID: 200311041112.17021.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tuesday 04 November 2003 10:06, Max Speransky wrote:
> Hello
>
> My task is to validate expression and get value of it in boolean variable.
> I try to do following:

> Ret := 3 || Op || $1;
> RETURN Ret;

> bill=# select get_value(3);
> WARNING: Error occurred while executing PL/pgSQL function get_value
> WARNING: line 6 at assignment
> ERROR: Bad boolean external representation '3=3'

The problem is that your expression is being evaluated as a string. In the
absence of an eval() function, you probably should do something like:

my_stmt := ''SELECT '' || 3 || Op || $1;
EXECUTE my_stmt;
FOR EACH ...

So - build a simple query, execute it and read the result. Should do what you
want.

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2003-11-04 11:14:14 Re: SELECT question
Previous Message Alex 2003-11-04 10:54:54 SELECT question