Skip to content

Handle PGRES_COMMAND_OK in pgresult_stream_any#447

Merged
larskanis merged 1 commit intoged:masterfrom
jeremyevans:command-ok-streaming
Mar 23, 2022
Merged

Handle PGRES_COMMAND_OK in pgresult_stream_any#447
larskanis merged 1 commit intoged:masterfrom
jeremyevans:command-ok-streaming

Conversation

@jeremyevans
Copy link
Copy Markdown
Contributor

Fixes usage when trying to stream the result of a procedure
call that returns no results.

Fixes Sequel tests when Sequel is set to stream all results.
Here's a reproducer that just uses ruby-pg without Sequel:

require 'pg'
conn = PG::Connection.new(user: "sequel_test")
conn.exec(<<END)
CREATE TABLE posts (a INTEGER);
CREATE OR REPLACE PROCEDURE test_procedure_posts()
LANGUAGE SQL
AS $$
INSERT INTO posts VALUES (1) RETURNING *;
INSERT INTO posts VALUES (2) RETURNING *;
SELECT max(posts.a), min(posts.a) FROM posts;
$$;
END
at_exit{conn.exec("DROP PROCEDURE test_procedure_posts(); DROP TABLE posts;")}

conn.send_query("CALL test_procedure_posts();")
conn.set_single_row_mode
# Next method call fails without patch:
# no result received - possibly an intersection with another result retrieval (PG::NoResultError)
conn.get_result.stream_each do |res|
  p [__LINE__, res]
end
conn.block

conn.send_query("CALL test_procedure_posts();")
conn.set_single_row_mode
while res = conn.get_result
  p [__LINE__, res]
end
conn.block

Fixes usage when trying to stream the result of a procedure
call that returns no results.
@larskanis larskanis merged commit 22e1a10 into ged:master Mar 23, 2022
@larskanis
Copy link
Copy Markdown
Collaborator

Thanks for working on this! Although single_row_mode is not intended for this use case, the change makes sense for consistency.

Not only the CALL command is affected but also INSERT, CREATE etc. So my test case is a bit simpler: ee4bf3d

Do you need a release with this change?

@jeremyevans
Copy link
Copy Markdown
Contributor Author

It seems like a corner case, so I don't think we need a release right away. We can wait for the normal release schedule.

@larskanis
Copy link
Copy Markdown
Collaborator

OK, thank you for working together once again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants