Re: BUG #1083: Insert query reordering interacts badly with - Mailing list pgsql-bugs

From Martin Langhoff
Subject Re: BUG #1083: Insert query reordering interacts badly with
Date
Msg-id 403B2BD4.1060908@catalyst.net.nz
Whole thread Raw
In response to Re: BUG #1083: Insert query reordering interacts badly with NEXTVAL()/CURRVAL()  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: BUG #1083: Insert query reordering interacts badly with  (Bruno Wolff III <bruno@wolff.to>)
List pgsql-bugs
Tom Lane wrote:

>How about
>
>SELECT nextval('seq');       -- ignore result
>
>INSERT INTO ... VALUES (currval('seq'), currval('seq'));
>
>

Well, it works for my sample case, I have to agree. Maybe I should
mention that I tried to boil down the bugreport to the simplest repro
case I could.

My actual SQL looks roughly like

    INSERT INTO destination (record_id, page, row)
    SELECT
        (SELECT record_id FROM record ORDERED BY name),
        (NEXTVAL('seq') / 200),
        (CURRVAL('seq') % 200)

While I have a workaround, I am definitely curious as to whether there
is actually a way to do it. Thanks for your patience.



regards,





martin

--
-----------------------------------------------------------------------
Martin @ Catalyst .Net .NZ  Ltd, PO Box 11-053, Manners St,  Wellington
WEB: http://catalyst.net.nz/           PHYS: Level 2, 150-154 Willis St
OFFICE: +64(4)916-7224                              MOB: +64(21)364-017
      Make things as simple as possible, but no simpler - Einstein
-----------------------------------------------------------------------

pgsql-bugs by date:

Previous
From: "Gary WAN"
Date:
Subject: The syntax about CREATE DOMAIN
Next
From: Richard Neill
Date:
Subject: Re: BUG #1082: Order by doesn't sort correctly.