Re: Obtain boolean value of expression in PLPGSQL

From: Pavel Stehule <stehule(at)kix(dot)fsv(dot)cvut(dot)cz>
To: Max Speransky <mx(at)lucky(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Obtain boolean value of expression in PLPGSQL
Date: 2003-11-04 14:11:22
Message-ID: Pine.LNX.4.44.0311041504050.12294-100000@kix.fsv.cvut.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello

You are on wrong way.

Try like

DECLARE
b RECORD;
s TEXT;
op TEXT;
BEGIN op := ''='';
s := ''SELECT 3 ''|| op || ''|| $1 || ''AS b'';
FOR b IN EXECUTE s LOOP
RETURN b.b;
END LOOP;
END;

Regards
Pavel

On Tue, 4 Nov 2003, Max Speransky wrote:

> Hello
>
> My task is to validate expression and get value of it in boolean variable.
> I try to do following:
> CREATE OR REPLACE FUNCTION get_value(integer) RETURNS boolean AS'
> DECLARE
> Ret boolean;
> Op TEXT = ''='';
> BEGIN
>
> Ret := 3 || Op || $1;
> RETURN Ret;
> END;
> ' language 'plpgsql';
>
> when I try to execute this function I get such result:
>
> 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'
> bill=#
>
> So, how can I explain that resulting type must be boolean ? Also, I try to
> play with SELECT INTO with same result.
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Sullivan 2003-11-04 14:18:23 Re: pg7.3.4: pg_atoi: zero-length string
Previous Message Edwin Quijada 2003-11-04 14:03:20 Problem with Pg_dumpall