Closed BrendanMartin closed 4 years ago
but how pq handle this case it hadled by sql package it self
This is a limitation of postgres, not pq. You can only have a single query if you are using parameters.
@mjibson : Just curious to revisit this. I see that this issue was solved in the JDBC driver: https://knowledgebase.progress.com/articles/Article/PostgreSQL-JDBC-driver-throws-cannot-insert-multiple-commands-into-a-prepared-statement-while-executing-multiple-prepared-statements
Is it possible to implement it in this module?
I have just run into this issue. Apparently this has been possible in postgres for quite a while but a simple query like this fails with the error above.
const sql: SQLStatement = SQL`
SELECT COUNT(*) FROM users;
SELECT * FROM users
LIMIT ${resultsPerPage}
OFFSET ${resultsPerPage * (page-1)}
`
Actually, I've just realised that if you omit the pagination from my example then it works fine. Returns an array of result sets so it can definitely handle multiple queries and multiple result sets, just not when using parameters. Weird.
I'm attempting to run two SELECT statements in one Query with arguments but I'm getting the error
pq: cannot insert multiple commands into a prepared statement
.A very contrived example of what I'm trying to do is this:
This creates the error above.
An example of how this should work is in the MultipleResultSets example under Query: https://golang.org/pkg/database/sql/#DB.Query