Skip to content

Incorrect multi-query results #1031

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

Open
alxivnov opened this issue Feb 6, 2025 · 0 comments
Open

Incorrect multi-query results #1031

alxivnov opened this issue Feb 6, 2025 · 0 comments

Comments

@alxivnov
Copy link

alxivnov commented Feb 6, 2025

  1. Try executing DELETE... ; UPDATE ...; SELECT ...;.
  2. Get result as an array of 2, where first element is an empty array.
  3. Expectation is to get array of 3 results, like [[], [], [...]].
  4. 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 = [[], [{}]]
		});
	});
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

No branches or pull requests

1 participant