-
Notifications
You must be signed in to change notification settings - Fork 285
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
sql.array error on empty array #49
Comments
ok digging deeper ive found out that console.log(sql.array([]));
// { type: 25, array: true, value: [] }
console.log(sql.array([1, 2, 3]));
// { type: 1700, array: true, value: [ 1, 2, 3 ] }
console.log(sql.array(['a', 'b', 'c']));
// { type: 25, array: true, value: [ 'a', 'b', 'c' ] } So temporary workaround is: const projectIds = [];
projectIds.type = 1700;
await sql`
UPDATE
users
SET
"projectIds" = ${sql.array(projectIds)}
WHERE
"id" = ${userId}
;
` Using the Line 105 in 758b5ee
Lines 220 to 226 in 758b5ee
Which is quite gruesome since I gotta remember the type number. Is it possible to have an optional second parameter of Kinda like ${sql.array([], 'string')} |
Would you mind trying master? |
Hi @porsager, It broke some unrelated parts unfortunately. I had this query before, it used to return plain integers before, but now I'm getting BigInt which is quite unexpected. const [transactionsPerPhase] = await sql`
SELECT
(SELECT
COUNT(transactions)
FROM transactions
WHERE "phaseId" = 0
AND "projectId" IN (${session.user.projectIds})
) AS "inPhase0",
(SELECT
COUNT(transactions)
FROM transactions
WHERE "phaseId" = 1
AND "projectId" IN (${session.user.projectIds})
) AS "inPhase1",
(SELECT
COUNT(transactions)
FROM transactions
WHERE "phaseId" = 2
AND "projectId" IN (${session.user.projectIds})
) AS "inPhase2",
(SELECT
COUNT(transactions)
FROM transactions
WHERE "phaseId" = 3
AND "projectId" IN (${session.user.projectIds})
) AS "inPhase3",
(SELECT
COUNT(transactions)
FROM transactions
WHERE "phaseId" = 4
AND "projectId" IN (${session.user.projectIds})
) AS "inPhase4",
(SELECT
COUNT(transactions)
FROM transactions
WHERE "phaseId" = 5
AND "projectId" IN (${session.user.projectIds})
) AS "inPhase5",
(SELECT
COUNT(transactions)
FROM transactions
WHERE "phaseId" = 6
AND "projectId" IN (${session.user.projectIds})
) AS "inPhase6",
(SELECT
COUNT(transactions)
FROM transactions
WHERE "phaseId" = 7
AND "projectId" IN (${session.user.projectIds})
) AS "inPhase7";
`;
return Object.values(transactionsPerPhase); transactionsPerPhase: [
1n, 0n, 0n, 0n,
0n, 0n, 0n, 0n
] |
Related /* eslint-disable no-console */
const sql = require('../db');
(async () => {
const projectIds = [];
await sql`
UPDATE
users
SET
"projectIds" = ${sql.array(projectIds)}
WHERE
"id" = ${5}
;
`;
})().then(console.log).catch(console.error);
|
Sorry, that's right. It's probably going to return |
I'll look into why the type doesn't fallback to letting Postgres decide for arrays. |
I got a "projectIds" field if
integer[]
with the following query:It works when it's not empty, but when empty I'm getting the following error:
Any way to fix this? Thank you.
The text was updated successfully, but these errors were encountered: