Re: = or := ? - Mailing list pgsql-general

From Michael Glaesemann
Subject Re: = or := ?
Date
Msg-id 3b7c1b3cf4eefa7ffce65ca2da69882e@myrealbox.com
Whole thread Raw
In response to = or := ?  ("Zlatko Matic" <zlatko.matic1@sb.t-com.hr>)
Responses Re: = or := ?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general

On May 9, 2005, at 18:00, Zlatko Matic wrote:

> This is a newbie question: what is the difference between using = and
> := in plpgsql function ?

In pl/pgsql,

:= is assignment
= is a logical comparison for equality

Some languages, such as perl, use = for assignment and == for logical
comparison.

x = 1
is a boolean result

x := 1
gives x the value of 1

Quick example:

    x := 2; -- gives x the value of 2

    IF (x = 1) THEN -- x = 1 is false
        x := 3;  -- skipped
    END IF;
    RETURN X; -- returns 2

Again:
    x := 1; -- gives x the value of 1

    IF (x = 1) THEN -- x = 1 is true
        x := 3;  -- perform assignment
    END IF;
    RETURN x; -- returns 3

Hope this helps.

Michael Glaesemann
grzm myrealbox com


pgsql-general by date:

Previous
From: "Zlatko Matic"
Date:
Subject: = or := ?
Next
From: "Masse Jacques"
Date:
Subject: Re: Adventures in Quest for GUI RAD