Incorrect multi-query results
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 8.7k
- Forks
- 374
- Avg merge
- 11d 16h
- Merged PRs (30d)
- 1
Description
- Try executing DELETE... ; UPDATE ...; SELECT ...;.
- Get result as an array of 2, where first element is an empty array.
- Expectation is to get array of 3 results, like
[[], [], [...]]. - Somehow all empty arrays from DELETE, UPDATE, INSERT get merged into one.
const postgres = require('postgres');
it('Multi-query', (done) => {
const db = postgres.default(CONNECTION_STRING);
const upd = /*sql*/`
UPDATE "settings"
SET "_json" = '[]'
WHERE "setting" = 'test';
--RETURNING "setting";
`;
const del = /*sql*/`
DELETE FROM "settings"
WHERE "setting" = 'test';
--RETURNING "setting";
`;
const ins = /*sql*/`
INSERT INTO "settings" ("package", "setting", "_json")
VALUES ('test', 'test', '{}')
ON CONFLICT ("package", "setting")
DO NOTHING;
--RETURNING "settings";
`;
const sel = /*sql*/`
SELECT "_json"
FROM "settings"
WHERE "setting" = 'test';
`;
Promise.allSettled([
db.unsafe(upd),
db.unsafe(del),
db.unsafe(ins),
db.unsafe(sel),
db.unsafe(del + del + ins + sel),
]).then(([upd, del, ins, sel, all]) => {
let success = upd.value.length == 0
&& del.value.length == 0
&& ins.value.length == 0
&& sel.value.length == 1
&& all.value.length == 4; // 4 sub-results: 0th, 1st, 2nd = [], 3rd = [{}]
done(success ? undefined : all.value.length); // actually, all.value = [[], [{}]]
});
});
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the db.unsafe entry point and reproduce the multi-statement case from the issue using DELETE, UPDATE, INSERT, and SELECT queries. Done means the combined query preserves one result array per statement, including separate empty arrays for the write statements.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs, postgresql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100