Thread: pl/pgsql and controling loops

pl/pgsql and controling loops

From
"Alain Roger"
Date:
Hi,

i've read several books extract about controlling loops in postgreSQL under pl/pgsql and there is something interesting.

once to do a comparison they use :
IF (ret == 1) THEN ...

once,
IF (ret = 1) THEN...

so are they both correct ?
comming from .NET/C++ world, usually we use '==' or '!=', so i expect that correct ones are '==' and '<>'.

moreover, when i check if the returned value "ret_email" from SELECT email INTO ret_email FROM tmp_newsletterreg WHERE tmp_usr_id = id_session;
i want to check if it is empty or not, so i do IF(ret_email <> '' ) THEN... but it does not work... every time it enter in the loop, even if it is empty string.

where is the problem ?

thx.

--
Alain
------------------------------------
Windows XP SP2
PostgreSQL 8.2.4 / MS SQL server 2005
Apache 2.2.4
PHP 5.2.4
C# 2005-2008

Re: pl/pgsql and controling loops

From
aklaver@comcast.net (Adrian Klaver)
Date:
 -------------- Original message ----------------------
From: "Alain Roger" <raf.news@gmail.com>
> Hi,
>
> i've read several books extract about controlling loops in postgreSQL under
> pl/pgsql and there is something interesting.
>
> once to do a comparison they use :
>
> > IF (ret == 1) THEN ...
>
>
> once,
>
> > IF (ret = 1) THEN...
>

Both are correct.

>
> so are they both correct ?
> comming from .NET/C++ world, usually we use '==' or '!=', so i expect that
> correct ones are '==' and '<>'.
>
> moreover, when i check if the returned value "ret_email" from SELECT email
> INTO ret_email FROM tmp_newsletterreg WHERE tmp_usr_id = id_session;
> i want to check if it is empty or not, so i do IF(ret_email <> '' ) THEN...
> but it does not work... every time it enter in the loop, even if it is empty
> string.
>
> where is the problem ?

Are you sure ret_email is an empty string and not a NULL value. <> won't work on a NULL value. You will need to use IS
NULLor IS NOT NULL. 
>
> thx.
>
> --
> Alain
> ------------------------------------
> Windows XP SP2
> PostgreSQL 8.2.4 / MS SQL server 2005
> Apache 2.2.4
> PHP 5.2.4
> C# 2005-2008

--
Adrian Klaver
aklaver@comcast.net


Re: pl/pgsql and controling loops

From
Tom Lane
Date:
aklaver@comcast.net (Adrian Klaver) writes:
> From: "Alain Roger" <raf.news@gmail.com>
>> once to do a comparison they use :
> IF (ret == 1) THEN ...
>> once,
> IF (ret = 1) THEN...

> Both are correct.

No they're not, as a simple test would convince you ...
there is no '==' operator in SQL.

            regards, tom lane

Re: pl/pgsql and controling loops

From
"Alain Roger"
Date:
this is what i did, and it's true that '==' does not exist under pl/pgsql. Only '=' should be used.


On Thu, Mar 27, 2008 at 8:53 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
aklaver@comcast.net (Adrian Klaver) writes:
> From: "Alain Roger" <raf.news@gmail.com>
>> once to do a comparison they use :
> IF (ret == 1) THEN ...
>> once,
> IF (ret = 1) THEN...

> Both are correct.

No they're not, as a simple test would convince you ...
there is no '==' operator in SQL.

                       regards, tom lane



--
Alain
------------------------------------
Windows XP SP2
PostgreSQL 8.2.4 / MS SQL server 2005
Apache 2.2.4
PHP 5.2.4
C# 2005-2008

Re: pl/pgsql and controling loops

From
aklaver@comcast.net (Adrian Klaver)
Date:
 -------------- Original message ----------------------
From: Tom Lane <tgl@sss.pgh.pa.us>
> aklaver@comcast.net (Adrian Klaver) writes:
> > From: "Alain Roger" <raf.news@gmail.com>
> >> once to do a comparison they use :
> > IF (ret == 1) THEN ...
> >> once,
> > IF (ret = 1) THEN...
>
> > Both are correct.
>
> No they're not, as a simple test would convince you ...
> there is no '==' operator in SQL.
>
>             regards, tom lane

I stand corrected.

--
Adrian Klaver
aklaver@comcast.net