public inbox for [email protected]
help / color / mirror / Atom feedFrom: Laurenz Albe <[email protected]>
To: Dominique Devienne <[email protected]>
To: [email protected]
Subject: Re: MVCC: Using function doing INSERT and returning PK in WHERE clause of SELECT statement
Date: Mon, 01 Jul 2024 14:29:48 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAFCRh-_R8Q2_=jeWpe+RWt798hhwAQLoPF=YG+nUnJXTg80qhA@mail.gmail.com>
References: <CAFCRh-_R8Q2_=jeWpe+RWt798hhwAQLoPF=YG+nUnJXTg80qhA@mail.gmail.com>
On Mon, 2024-07-01 at 10:33 +0200, Dominique Devienne wrote:
> INSERT'ing a new row is wrapped in a DEFINER function,
> that returns the newly inserted row's OK (and integral ID).
>
> And in the code calling that function, I was
>
> SELECT * FROM table WHERE ID = insert_row_via_func(....)
>
> to "save a round trip", combining the insertion and the select.
> But of course, it didn't work, and in hindsight, the SCN for the
> SELECT is chosen before the INSERT done inside the function,
> so the new row is not seen, and the select returns nothing.
>
> Is my analysis correct? In terms of the problem?
> And the solutions / work-arounds?
That looks corrent.
Just define the function as RETURNS "table"
and use INSERT ... RETURNING *
Yours,
Laurenz Albe
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: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: MVCC: Using function doing INSERT and returning PK in WHERE clause of SELECT statement
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox