From: Peter J. Holzer <hjp-pgsql@hjp.at>
To: pgsql-general@lists.postgresql.org
Subject: Re: execute block like Firebird does
Date: Wed, 30 May 2018 22:25:04 +0200
Message-ID: <20180530202504.vlt7iiis2tu3ku3p@hjp.at> (raw)
In-Reply-To: <CANVwZtsGAYMugW+W7WGGH7Ck3YFV4zB6NvnkwRBXi14XQdpaug@mail.gmail.com>
References: <1518328644815-0.post@n3.nabble.com>
<1527684659736-0.post@n3.nabble.com>
<CANVwZtsGAYMugW+W7WGGH7Ck3YFV4zB6NvnkwRBXi14XQdpaug@mail.gmail.com>
On 2018-05-30 15:16:56 +0200, Félix GERZAGUET wrote:
> On Wed, May 30, 2018 at 2:50 PM, PegoraroF10 <marcos@f10.com.br> wrote:
> So, is that possible to change a DO structure is ran, to be possible to
> return one or more values ?
> It would be like ...
> DO returns(ID Integer, Description Text) as
> $$
> begin
> select ...
> insert ...
> select ... into ID, Description
> end
> $$
>
> Using this way would be possible to create that script on client, call it
> just one time and have a result for that execution, exactly the way a
> "execute block" does on Firebird.
[...]
>
> Since you seems to be able to construct dynamically the statement from the
> client application, I think it is already possible to do that in one SQL
> statement using CTE.
[...]
> So you can construct arbitrary complex thing using any combination of SELECT,
> UPDATE and DELETE.
But note that:
| The sub-statements in WITH are executed concurrently with each other and
| with the main query. Therefore, when using data-modifying statements in
| WITH, the order in which the specified updates actually happen is
| unpredictable. All the statements are executed with the same snapshot
| (see Chapter 13), so they cannot “see” one another's effects on the
| target tables. This alleviates the effects of the unpredictability of
| the actual order of row updates, and means that RETURNING data is the
| only way to communicate changes between different WITH sub-statements
| and the main query.
-- https://www.postgresql.org/docs/10/static/queries-with.html#QUERIES-WITH-MODIFYING
In a DO block the statements are processed sequentially and each
statement sees the results of the previous statements.
hp
--
_ | Peter J. Holzer | we build much bigger, better disasters now
|_|_) | | because we have much more sophisticated
| | | hjp@hjp.at | management tools.
__/ | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/;
Attachments:
signature.asc (application/pgp-signature, 832B) download
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: hjp-pgsql@hjp.at
Subject: Re: execute block like Firebird does
In-Reply-To: <20180530202504.vlt7iiis2tu3ku3p@hjp.at>
References: <1518328644815-0.post@n3.nabble.com> <1527684659736-0.post@n3.nabble.com> <CANVwZtsGAYMugW+W7WGGH7Ck3YFV4zB6NvnkwRBXi14XQdpaug@mail.gmail.com> <20180530202504.vlt7iiis2tu3ku3p@hjp.at>
* 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