-
Notifications
You must be signed in to change notification settings - Fork 288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Long queries with parameters #303
Comments
My example above is contrived, and for a more realistic example we can use a common pattern of running DB logic in parallel like so - // test2.mjs
import postgres from "postgres";
const sql = postgres({
// The issue happens when two queries are executed sequentially over the same connection
// It also happens with any number of connections, but easier to demo with a single network connection to schedule the queries predictably
max: 1,
});
const res = await Promise.all([
// run IO-heavy functions in parallel
fetchInfo(1),
calcSum(1, 2, 3),
]);
async function fetchInfo(someValue) {
// Calling .unsafe will throw, calling sql`` will just hang
// const padding = ".".repeat(16_342);
// const info = await sql.unsafe(`SELECT 0+$1 /*${padding} */`, [someValue]);
const info =
await sql`SELECT 0+${1} /*...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................*/`;
// do some post-processing of $info, then return it
return info;
}
async function calcSum(val1, val2, val3) {
// Calling .unsafe will throw, calling sql`` will just hang
// const info = await sql.unsafe(`SELECT 0+$1+$2+$3`, [val1, val2, val3]);
const info = await sql`SELECT 0+${val1}+${val2}+${val3}`;
// do some post-processing of $info, then return it
return info;
} |
@eugene1g Very nice find, and a great description! This is happening due to drain implicitly dequeueing the next query even if a query is currently in the describe phase (waiting for response). That results in describe being sent for the second query before sending the parameters for the first. I'll push a fix ASAP! |
Amazing |
|
I have a custom query builder to help users run complex queries against the database using parameters to apply various filters. This query builder can generate really long queries, but not long enough to be a problem for PG. However, running those long queries with
postgres
doesn't work right now when those queries use parameters.My real code is too complex to be useful, but here's a simple contrived example -
The specific error I get is -
It vaguely feels like the problem would be in the network serialization logic - perhaps some Buffer is overflowing or not being cleared - but I haven't narrowed this down further.
The text was updated successfully, but these errors were encountered: