postgres-nio icon indicating copy to clipboard operation
postgres-nio copied to clipboard

Support simple queries, to support multiple queries in a single command

Open NeedleInAJayStack opened this issue 4 years ago • 4 comments

Describe the bug

When evaluating multiple insert statements in a deferred query, versions <= 1.4.4 would succeed, but >= 1.5.0 will fail with the message "cannot insert multiple commands into a prepared statement"

To Reproduce

Use postgres-nio version >= 1.5.0, and run the following on a test database:

try postgres.simpleQuery("""
CREATE TABLE test (
    user_id serial PRIMARY KEY,
    username VARCHAR ( 50 ) UNIQUE NOT NULL
);
""").wait()

try postgres.simpleQuery("""
SET CONSTRAINTS ALL DEFERRED;
INSERT INTO "test" ("user_id", "username") VALUES ('1', 'user1');
INSERT INTO "test" ("user_id", "username") VALUES ('2', 'user2');
INSERT INTO "test" ("user_id", "username") VALUES ('3', 'user3');
INSERT INTO "test" ("user_id", "username") VALUES ('4', 'user4');
INSERT INTO "test" ("user_id", "username") VALUES ('5', 'user5');
COMMIT;
""").wait()

Expected behavior

That it would complete successfully with the rows inserted into the table. This is the behavior in versions <= 1.4.4.

Environment

This was tested with postgres-kit v2.3.0, and varying versions of postgres-nio.

  • Vapor Framework version: N/A, this was observed with only postgres-nio and postgres-kit dependencies
  • Vapor Toolbox version: N/A, this was observed with only postgres-nio and postgres-kit dependencies
  • OS version: macOS Big Sur v11.2.1

NeedleInAJayStack avatar Feb 26 '21 23:02 NeedleInAJayStack

@NeedleInAJayStack Thanks for raising this issue. Work on this has begun: https://github.com/vapor/postgres-nio/pull/146

fabianfett avatar Feb 28 '21 11:02 fabianfett

Thanks @fabianfett! Let me know if I can help.

NeedleInAJayStack avatar Mar 03 '21 00:03 NeedleInAJayStack

I also stumbled upon this error and added a procedure in the database to be called from my web app as a (at least preliminary) solution.

stefanspringer1 avatar Apr 09 '21 12:04 stefanspringer1

Hi, is there any update on this?

Kishimotovn avatar Nov 21 '22 01:11 Kishimotovn