Re: hi, what is wrong with my newbie sql?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Ronin" <jkoorts(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: hi, what is wrong with my newbie sql?
Date: 2006-09-27 19:21:15
Message-ID: 5643.1159384875@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Ronin" <jkoorts(at)gmail(dot)com> writes:
> k = 10;
> FOR k IN 1..10 LOOP
> k = k +1;
> END LOOP;

> return k;

An integer for-loop implicitly declares its control variable, so the "k"
inside the loop is unrelated to the "k" outside. Hence you get 10.

As for what you'd get if they were the same variable, I dunno why you're
so certain it would be 20. Munging a loop's control variable by hand is
a good way to trip over undocumented details of the loop implementation.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Paolo Saudin 2006-09-27 19:29:42 Cumulative aggregate
Previous Message Andreas Kretschmer 2006-09-27 19:14:31 Re: hi, what is wrong with my newbie sql?