pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Alvaro Herrera <alvherre@commandprompt.com>
Cc: Shane Ambler <pgsql@Sheeky.Biz>
Cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Cc: Stephan Szabo <sszabo@megazone.bigpanda.com>
Cc: Jeff Frost <jeff@frostconsultingllc.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: [HACKERS] Why does the sequence skip a number with generate_series?
Date: Thu, 04 Oct 2007 11:18:16 -0400
Message-ID: <21286.1191511096@sss.pgh.pa.us> (raw)
In-Reply-To: <20071004144656.GK6176@alvh.no-ip.org>
References: <Pine.LNX.4.64.0710021716490.4701@discord.home.frostconsultingllc.com>
	<20071003175808.P16566@megazone.bigpanda.com>
	<4704F7CA.4070200@Sheeky.Biz>
	<20071004144656.GK6176@alvh.no-ip.org>

Alvaro Herrera <alvherre@commandprompt.com> 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



view thread (6+ messages)  latest in thread

Message-ID: <21286.1191511096@sss.pgh.pa.us>
Permalink:  ../21286.1191511096@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/21286.1191511096@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, alvherre@commandprompt.com, pgsql@Sheeky.Biz, pgsql-hackers@postgresql.org, sszabo@megazone.bigpanda.com, jeff@frostconsultingllc.com
  Subject: Re: [HACKERS] Why does the sequence skip a number with generate_series?
  In-Reply-To: <21286.1191511096@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox