Re: Obtain boolean value of expression in PLPGSQL - Mailing list pgsql-general

From Richard Huxton
Subject Re: Obtain boolean value of expression in PLPGSQL
Date
Msg-id 200311041112.17021.dev@archonet.com
Whole thread Raw
In response to Obtain boolean value of expression in PLPGSQL  (Max Speransky <mx@lucky.net>)
List 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

pgsql-general by date:

Previous
From: Alex
Date:
Subject: SELECT question
Next
From: Richard Huxton
Date:
Subject: Re: SELECT question