Re: [SQL] Why does the sequence skip a number with generate_series?

From: Shane Ambler <pgsql(at)Sheeky(dot)Biz>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [SQL] Why does the sequence skip a number with generate_series?
Date: 2007-10-06 00:50:00
Message-ID: 4706DBB8.8010000@Sheeky.Biz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql

Tom Lane wrote:
> Alvaro Herrera <alvherre(at)commandprompt(dot)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

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(at)Sheeky(dot)Biz

Get Sheeky @ http://Sheeky.Biz

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2007-10-06 15:15:55 Re: Encoding and i18n
Previous Message Gregory Stark 2007-10-05 22:18:21 Encoding and i18n

Browse pgsql-sql by date

  From Date Subject
Next Message Rodrigo De León 2007-10-07 19:16:16 Re: SQL query question
Previous Message Aroon Pahwa 2007-10-05 21:33:20 valid query runs forever?