Question about "compound" queries.

Started by Anton A. Melnikovabout 3 years ago3 messages
#1Anton A. Melnikov
aamelnikov@inbox.ru

Hello!

Please, could somebody explain what the "compound" queries were created for?
Maybe i'm calling them wrong. It's about queries like:
SELECT 1 + 2 \; SELECT 2.0 AS "float" \; SELECT 1;

Such queries can neither be prepared nor used in the extended protocol with
ERROR: cannot insert multiple commands into a prepared statement.
What are their advantages?
And what is the proper name for such queries? "Compound" or something else?
Would be very grateful for clarification.

Best wishes,

--
Anton A. Melnikov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

#2David G. Johnston
david.g.johnston@gmail.com
In reply to: Anton A. Melnikov (#1)
Re: Question about "compound" queries.

On Mon, Oct 24, 2022 at 3:02 PM Anton A. Melnikov <aamelnikov@inbox.ru>
wrote:

Hello!

Please, could somebody explain what the "compound" queries were created
for?
Maybe i'm calling them wrong. It's about queries like:
SELECT 1 + 2 \; SELECT 2.0 AS "float" \; SELECT 1;

Such queries can neither be prepared nor used in the extended protocol with
ERROR: cannot insert multiple commands into a prepared statement.
What are their advantages?
And what is the proper name for such queries? "Compound" or something else?
Would be very grateful for clarification.

I suspect they came about out of simplicity - being able to simply take a
text file with a bunch of SQL commands in a script and send them as-is to
the server without any client-side parsing and let the server just deal
with it. It works because the system needs to do those kinds of things
anyway so, why not make it user-facing, even if most uses would find its
restrictions makes it undesirable to use.

David J.

#3Anton A. Melnikov
aamelnikov@inbox.ru
In reply to: David G. Johnston (#2)
Re: Question about "compound" queries.

Thanks a lot for the reply and timely help!

On 25.10.2022 01:36, David G. Johnston wrote:

I suspect they came about out of simplicity - being able to simply take a text file with a bunch of SQL commands in a script and send them as-is to the server without any client-side parsing and let the server just deal with it.  It works because the system needs to do those kinds of things anyway so, why not make it user-facing, even if most uses would find its restrictions makes it undesirable to use.

David J.

All the best,

--
Anton A. Melnikov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company