From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Bryn Llewellyn <bryn@yugabyte.com>
Cc: Tom Lane PostgreSQL <tgl@sss.pgh.pa.us>
Cc: pgsql-general list <pgsql-general@lists.postgresql.org>
Subject: Re: Why can't I have a "language sql" anonymous block?
Date: Tue, 14 Dec 2021 12:47:09 -0800
Message-ID: <a478ed89-aa3b-e55c-79ee-259fad6ff28f@aklaver.com> (raw)
In-Reply-To: <05E2EA9E-B353-4D69-B255-3BAAA5954936@yugabyte.com>
References: <C9838A29-8C84-4F68-9C41-5CB4665911E5@yugabyte.com>
<872342.1639428817@sss.pgh.pa.us>
<FBBBFEDF-4023-4A38-B1BE-FC07423E0C46@yugabyte.com>
<79c43dc2-f0f6-1ad8-82b4-da5ba536fdf5@aklaver.com>
<05E2EA9E-B353-4D69-B255-3BAAA5954936@yugabyte.com>
On 12/14/21 11:30, Bryn Llewellyn wrote:
> /Adrian Klaver wrote:/
>
> /Bryn wrote:/
>
> Thanks for the links to the articles on the inlining of “language sql”
> functions into SQL statements that use them. (I noted “the exact
> conditions which apply to inlining are somewhat complex and not well
> documented outside the source code” in the PG Wiki.) This optimization
> is interesting. But its discussion is orthogonal to the question that I
> asked.
You asked:
"There must be a reason to prefer a “language sql” procedure over a
“language plpgsql” procedure—otherwise the former wouldn’t be supported."
I provided two reasons, or did I misread that?
> It would seem, on its face, that the DO block is preferable because it
> uses a single server call from the client rather than four. (Maybe it’s
> two server calls if the implementation of autocommit is done client-side
> by sending a follow-up “commit”.) I do know that at least some client
> languages that have a PG driver allow many SQL statements to be sent in
> a single call. I’ve heard that psql will do this if all the statements
> are on one line. But I can’t find anything in the PG docs about this. Is
> it true? And if so, where is it documented? However, this just feels far
> less like a clear way to ask for what you want than a DO block. And it
> would lead to unreadable code with only a small number of to-be-batched
> SQL statements.
Seems to work for the tests:
https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/test/regress/sql/timestamp.sql;h=e0...>
> All this aside, as long as DO blocks don’t allow their contained
> statements to be parameterized, you anyway have to use a procedure to
> get the functionality that you need. This makes my question largely
> moot—as Tom implied. So I’ll simply hope that, one day, the PostgreSQL
> guardians will concede that implementing this missing DO functionality
> would be useful—just as the Oracle Database guardians decided three
> decades ago—and bring that functionality in a future PG release.
My experience is when I get to the point of needing parameters I'm
pretty much going to need the other plpgsql features. I could see having
it, but I do not remember seeing any/many previous posts to this list
requesting it. That pushes it down to the bottom of the must haves.
--
Adrian Klaver
adrian.klaver@aklaver.com
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: adrian.klaver@aklaver.com, bryn@yugabyte.com, tgl@sss.pgh.pa.us
Subject: Re: Why can't I have a "language sql" anonymous block?
In-Reply-To: <a478ed89-aa3b-e55c-79ee-259fad6ff28f@aklaver.com>
References: <C9838A29-8C84-4F68-9C41-5CB4665911E5@yugabyte.com> <872342.1639428817@sss.pgh.pa.us> <FBBBFEDF-4023-4A38-B1BE-FC07423E0C46@yugabyte.com> <79c43dc2-f0f6-1ad8-82b4-da5ba536fdf5@aklaver.com> <05E2EA9E-B353-4D69-B255-3BAAA5954936@yugabyte.com> <a478ed89-aa3b-e55c-79ee-259fad6ff28f@aklaver.com>
* 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