Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

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



"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



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group