Re: PL/pgSQL 'i = i + 1' Syntax
От | David Wheeler |
---|---|
Тема | Re: PL/pgSQL 'i = i + 1' Syntax |
Дата | |
Msg-id | 6570E265-A68F-499E-9019-2F28DDC7464D@kineticode.com обсуждение исходный текст |
Ответ на | Re: PL/pgSQL 'i = i + 1' Syntax (Mark Dilger <pgsql@markdilger.com>) |
Список | pgsql-hackers |
On May 16, 2006, at 16:42, Mark Dilger wrote: > So I don't know why it works for you. I wrote the following, and > it also > increments the variable: > > CREATE OR REPLACE FUNCTION weird () RETURNS SETOF INT AS $$ > DECLARE > i integer; > BEGIN > i := 0; > return next i; > i = i + 1; > return next i; > i = i + 1; > return next i; > return; > END; > $$ LANGUAGE plpgsql; > > So I don't think it has anything to do with loop variables, > specifically. Indeed. It appears that, contrary to what I previously thought, := also works: CREATE OR REPLACE FUNCTION inc_by_two( upfrom int, upto int ) RETURNS SETOF INT AS $$ BEGIN FOR i IN upfrom..upto LOOP RETURN NEXT i; i := i + 1; END LOOP; END; $$ LANGUAGE 'plpgsql'; try=# select * from inc_by_two(1,11); inc_by_two ------------ 1 3 5 7 9 11 (6 rows) Best, David
В списке pgsql-hackers по дате отправления: