Re: psql FETCH_COUNT feature does not work with combined queries

2020-09-30 Thread Michael Paquier
On Thu, Jul 16, 2020 at 04:44:47PM -0700, David G. Johnston wrote:
> When FETCH_COUNT is non-zero, and you send a multi-statement command
> to the server (for example via -c or the \; meta-command), the results
> are undefined. This combination is presently allowed for backward
> compatibility.

This has been waiting on author for two months now, so I have marked
the patch as RwF in the CF app.
--
Michael


signature.asc
Description: PGP signature


Re: psql FETCH_COUNT feature does not work with combined queries

2020-07-16 Thread David G. Johnston
On Thu, Jul 16, 2020 at 4:24 PM Alvaro Herrera 
wrote:

> On 2020-Jul-16, David Johnston wrote:
>
> > Instead of a note maybe add a paragraph stating:
> >
> > "This setting is ignored when multiple statements are sent to the server
> as a single command (i.e., via the -c command line option or the \;
> meta-command).  Additionally, it is possible for certain combinations of
> statements sent in that manner to instead return no results, or even be
> ignored, instead of returning the result set of the last query.  In short,
> when FETCH_COUNT is non-zero, and you send a multi-statement command to the
> server, the results are undefined. This combination in presently allowed
> for backward compatibility."
>
> I personally dislike documenting things that don't work, if worded in a
> way that don't leave open the possibility of fixing it in the future.
> So I didn't like Fabien's original wording either, though I was thinking
> that just adding "This may change in a future release of Postgres" might
> have been enough.  That seems more difficult with your proposed wording,
> but maybe you see a good way to do it?
>
> After rereading it a few times, I think it's too specific about how it
> fails.  Maybe it's possible to reduce to just the last two phrases,
> along the lines of
>
> > When FETCH_COUNT is non-zero, and you send a multi-statement command
> > to the server (for example via -c or the \; meta-command), the results
> > are undefined. This combination in presently allowed for backward
> > compatibility and may be changed in a future release.
>
>
Everything may change in a future release so I am generally opposed to
including that.  But I'm ok with being less descriptive on the observed
failure modes and sweeping it all under "undefined".  Need to fix my typo,
"This combination is presently allowed".

When FETCH_COUNT is non-zero, and you send a multi-statement command
to the server (for example via -c or the \; meta-command), the results
are undefined. This combination is presently allowed for backward
compatibility.

David J.


Re: psql FETCH_COUNT feature does not work with combined queries

2020-07-16 Thread Alvaro Herrera
On 2020-Jul-16, David Johnston wrote:

> Instead of a note maybe add a paragraph stating:
> 
> "This setting is ignored when multiple statements are sent to the server as a 
> single command (i.e., via the -c command line option or the \; meta-command). 
>  Additionally, it is possible for certain combinations of statements sent in 
> that manner to instead return no results, or even be ignored, instead of 
> returning the result set of the last query.  In short, when FETCH_COUNT is 
> non-zero, and you send a multi-statement command to the server, the results 
> are undefined. This combination in presently allowed for backward 
> compatibility."

I personally dislike documenting things that don't work, if worded in a
way that don't leave open the possibility of fixing it in the future.
So I didn't like Fabien's original wording either, though I was thinking
that just adding "This may change in a future release of Postgres" might
have been enough.  That seems more difficult with your proposed wording,
but maybe you see a good way to do it?

After rereading it a few times, I think it's too specific about how it
fails.  Maybe it's possible to reduce to just the last two phrases,
along the lines of

> When FETCH_COUNT is non-zero, and you send a multi-statement command
> to the server (for example via -c or the \; meta-command), the results
> are undefined. This combination in presently allowed for backward
> compatibility and may be changed in a future release.

-- 
Álvaro Herrerahttps://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services




Re: psql FETCH_COUNT feature does not work with combined queries

2020-07-16 Thread David Johnston
The following review has been posted through the commitfest application:
make installcheck-world:  not tested
Implements feature:   not tested
Spec compliant:   not tested
Documentation:tested, passed

Fabien,

There is a minor typo (works -> work) but overall I'm not a fan of the wording.

Instead of a note maybe add a paragraph stating:

"This setting is ignored when multiple statements are sent to the server as a 
single command (i.e., via the -c command line option or the \; meta-command).  
Additionally, it is possible for certain combinations of statements sent in 
that manner to instead return no results, or even be ignored, instead of 
returning the result set of the last query.  In short, when FETCH_COUNT is 
non-zero, and you send a multi-statement command to the server, the results are 
undefined. This combination in presently allowed for backward compatibility."

I would suggest, however, adding some tests in src/test/psql.sql demonstrating 
the broken behavior.  A potentially useful test setup would be:
create temp table testtbl (idx int, div int);
insert into testtbl (1,1), (2,1),(3,1),(4,0),(5,1);
and combine that with FETCH_COUNT 3

Some other things I tried, with and without FETCH_COUNT:

begin \; select 2 \; commit \; select 1 / div from (select div from testtbl 
order by idx) as src;
select 1/0 \; select 1 / div from (select div from testtbl where div <> 0 order 
by idx) as src;
begin \; select 2 \; select 1 \; commit;
begin \; select 2 \; select 1;
commit;

I'm not sure how to go about getting a equivalent result of "select pg_sleep(2) 
\; select 1;" not sleeping.  If I put select 1/0 instead of pg_sleep I get an 
error and any DML seems to end up working just fine (minus actual batch 
fetching)
update testtbl set val = 2 \; select 1; --result (1)

David J.

The new status of this patch is: Waiting on Author


Re: psql FETCH_COUNT feature does not work with combined queries

2020-03-27 Thread Fabien COELHO



Assuming there's no one willing to fix the behavior (and that seems
unlikely given we're in the middle of a 2020-01 commitfest) it makes
sense to at least document the behavior.

That being said, I think the proposed patch may be a tad too brief. I
don't think we need to describe the exact behavior, of course, but maybe
it'd be good to mention that the behavior depends on the type of the
last command etc. Also, I don't think "combined query" is a term used
anywhere in the code/docs - I think the proper term is "multi-query
string".


Any thoughts on Tomas' comments?


Sorry, I did not notice them.

I tried "multi-command", matching some wording use elsewhere in the file. 
I'm at lost about how to describe the insane behavior the feature has when 
they are used, which is really just an unfixed bug, so I expanded a minima 
in the attached v2.


--
Fabien.diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index 402c4b1b26..b4a9fc3b60 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -3781,6 +3781,14 @@ bar
 fail after having already displayed some rows.
 
 
+
+
+This feature does not works properly with multi-command
+(\;) queries as it depends on the command
+types encountered in the string.
+
+
+
 
 
 Although you can use any output format with this feature,


Re: psql FETCH_COUNT feature does not work with combined queries

2020-03-27 Thread David Steele

Hi Fabien,

On 1/6/20 5:20 PM, Tomas Vondra wrote:

On Fri, Jul 26, 2019 at 04:13:23PM +, Fabien COELHO wrote:


FETCH_COUNT does not work with combined queries, and probably has 
never worked since 2006.


For the record, this bug has already been reported & discussed by 
Daniel Vérité a few months back, see:


https://www.postgresql.org/message-id/flat/a0a854b6-563c-4a11-bf1c-d6c6f924004d%40manitou-mail.org 



Given the points of view expressed on this thread, especially Tom's 
view against improving the lexer used by psql to known where query 
ends, it looks that my documentation patch is the way to go in the 
short term, and that if the "always show query results" patch is 
committed, it might simplify a bit solving this issue as the PQexec 
call is turned into PQsendQuery.




Assuming there's no one willing to fix the behavior (and that seems
unlikely given we're in the middle of a 2020-01 commitfest) it makes
sense to at least document the behavior.

That being said, I think the proposed patch may be a tad too brief. I
don't think we need to describe the exact behavior, of course, but maybe
it'd be good to mention that the behavior depends on the type of the
last command etc. Also, I don't think "combined query" is a term used
anywhere in the code/docs - I think the proper term is "multi-query
string".


Any thoughts on Tomas' comments?

I'll mark this Waiting on Author because I feel like some response 
and/or a new patch is needed.


Regards,
--
-David
da...@pgmasters.net




Re: psql FETCH_COUNT feature does not work with combined queries

2020-01-06 Thread Tomas Vondra

On Fri, Jul 26, 2019 at 04:13:23PM +, Fabien COELHO wrote:


FETCH_COUNT does not work with combined queries, and probably has 
never worked since 2006.


For the record, this bug has already been reported & discussed by 
Daniel Vérité a few months back, see:


https://www.postgresql.org/message-id/flat/a0a854b6-563c-4a11-bf1c-d6c6f924004d%40manitou-mail.org

Given the points of view expressed on this thread, especially Tom's 
view against improving the lexer used by psql to known where query 
ends, it looks that my documentation patch is the way to go in the 
short term, and that if the "always show query results" patch is 
committed, it might simplify a bit solving this issue as the PQexec 
call is turned into PQsendQuery.




Assuming there's no one willing to fix the behavior (and that seems
unlikely given we're in the middle of a 2020-01 commitfest) it makes
sense to at least document the behavior.

That being said, I think the proposed patch may be a tad too brief. I
don't think we need to describe the exact behavior, of course, but maybe
it'd be good to mention that the behavior depends on the type of the
last command etc. Also, I don't think "combined query" is a term used
anywhere in the code/docs - I think the proper term is "multi-query
string".


regards

--
Tomas Vondra  http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services




Re: psql FETCH_COUNT feature does not work with combined queries

2019-07-26 Thread Fabien COELHO


FETCH_COUNT does not work with combined queries, and probably has never 
worked since 2006.


For the record, this bug has already been reported & discussed by Daniel 
Vérité a few months back, see:


https://www.postgresql.org/message-id/flat/a0a854b6-563c-4a11-bf1c-d6c6f924004d%40manitou-mail.org

Given the points of view expressed on this thread, especially Tom's view 
against improving the lexer used by psql to known where query ends, it 
looks that my documentation patch is the way to go in the short term, and 
that if the "always show query results" patch is committed, it might 
simplify a bit solving this issue as the PQexec call is turned into 
PQsendQuery.



--
Fabien.