using = in a function

Started by Andy Colsonabout 18 years ago3 messagesgeneral
Jump to latest
#1Andy Colson
andy@squeakycode.net

Hi all,

I was reading the doc's on functions when I came across this:

"
An assignment of a value to a PL/pgSQL variable or row/record field is
written as:

variable := expression;
"

and I realized, I didn't do that! My assignments look like:

tmp = extract(minute from result);
if tmp > 30 then
tmp = 60 - tmp;
offset = tmp || ' minutes';
result = result + offset;
else
offset = tmp || ' minutes';
result = result - offset;
end if;

Notice I just use = and not :=.

My question is, is there a difference? It seems to work both ways, so
I'm a little confused.

Thanks,

-Andy

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andy Colson (#1)
Re: using = in a function

Andy Colson <andy@squeakycode.net> writes:

An assignment of a value to a PL/pgSQL variable or row/record field is
written as:
variable := expression;

Notice I just use = and not :=.

My question is, is there a difference? It seems to work both ways, so
I'm a little confused.

Yeah, plpgsql actually allows both, but it's not documented.

regards, tom lane

In reply to: Tom Lane (#2)
Re: using = in a function

On 29/01/2008 02:41, Tom Lane wrote:

Andy Colson <andy@squeakycode.net> writes:

Notice I just use = and not :=.

[snip]

Yeah, plpgsql actually allows both, but it's not documented.

I really like := 'cos I've used Delphi/Pascal a lot over the years, so
:= falls nicely under the fingers. :-)

Ray.

---------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod@iol.ie
---------------------------------------------------------------