Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 7ADF59FB26A for ; Fri, 5 Oct 2007 21:50:10 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 63530-10 for ; Fri, 5 Oct 2007 21:50:06 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from ipmail02.adl2.internode.on.net (ipmail02.adl2.internode.on.net [203.16.214.141]) by postgresql.org (Postfix) with ESMTP id D70919F9926 for ; Fri, 5 Oct 2007 21:50:05 -0300 (ADT) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AusRAAN2BkfLevdH/2dsb2JhbAAugSs X-IronPort-AV: E=Sophos;i="4.21,238,1188743400"; d="scan'208";a="201500034" Received: from ppp247-71.static.internode.on.net (HELO DevBox.local) ([203.122.247.71]) by ipmail02.adl2.internode.on.net with ESMTP; 06 Oct 2007 10:20:01 +0930 Message-ID: <4706DBB8.8010000@Sheeky.Biz> Date: Sat, 06 Oct 2007 10:20:00 +0930 From: Shane Ambler User-Agent: Thunderbird 2.0.0.6 (Macintosh/20070728) MIME-Version: 1.0 To: Tom Lane CC: PostgreSQL Hackers Subject: Re: [SQL] Why does the sequence skip a number with generate_series? References: <20071003175808.P16566@megazone.bigpanda.com> <4704F7CA.4070200@Sheeky.Biz> <20071004144656.GK6176@alvh.no-ip.org> <21286.1191511096@sss.pgh.pa.us> In-Reply-To: <21286.1191511096@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/201 X-Sequence-Number: 108569 Tom Lane wrote: > Alvaro Herrera writes: >> Shane Ambler wrote: >>>> CREATE TABLE jefftest ( id serial, num int ); >>>> INSERT INTO jefftest (num) values (generate_series(1,10)); >>>> INSERT INTO jefftest (num) values (generate_series(11,20)); >>>> INSERT INTO jefftest (num) values (generate_series(21,30)); > >> Don't use set-returning functions in "scalar context". > > I think what is actually happening is that the expanded targetlist is > > nextval('seq'), generate_series(1,10) > > On the eleventh iteration, generate_series() returns ExprEndResult to > show that it's done ... but the 11th nextval() call already happened. > If you switched the columns around, you wouldn't get the extra call. > > If you think that's bad, the behavior with multiple set-returning > functions in the same targetlist is even stranger. The whole thing > is a mess and certainly not something we would've invented if we > hadn't inherited it from Berkeley. > > regards, tom lane Would a re-write be something worth adding to the todo list? and/or maybe add something about this to the manual? -- Shane Ambler pgSQL@Sheeky.Biz Get Sheeky @ http://Sheeky.Biz