PostgresError: syntax error at or near "$1"

const stock = await this.db.query.StockM.findMany({
where: (m, { inArray, eq, and }) =>
and(inArray(m.checkCode, checkCode), eq(m.game, game as Game)),
});
const stock = await this.db.query.StockM.findMany({
where: (m, { inArray, eq, and }) =>
and(inArray(m.checkCode, checkCode), eq(m.game, game as Game)),
});
------------- [DATABASE LOG QUERY] ------------
[TIME: 2024-01-14 20:55:05]

Query: select "id", "owner", "game", "code_type", "code", "check_code", "on_use", "on_backup", "is_used", "used_for", "is_bought", "lastUpdate", "price", "created_at" from "stock" "StockM" where ("StockM"."check_code" in $1 and "StockM"."game" = $2) -- params: ["20:T-S-00069405 8977-3373-6717-7449+UNIPIN_VOUCHER", "FREE_FIRE"]

---------------------------------------------------
------------- [DATABASE LOG QUERY] ------------
[TIME: 2024-01-14 20:55:05]

Query: select "id", "owner", "game", "code_type", "code", "check_code", "on_use", "on_backup", "is_used", "used_for", "is_bought", "lastUpdate", "price", "created_at" from "stock" "StockM" where ("StockM"."check_code" in $1 and "StockM"."game" = $2) -- params: ["20:T-S-00069405 8977-3373-6717-7449+UNIPIN_VOUCHER", "FREE_FIRE"]

---------------------------------------------------
[Nest] 1347376 - 01/14/2024, 8:55:05 PM ERROR [ExceptionsHandler] syntax error at or near "$1"
PostgresError: syntax error at or near "$1"
at ErrorResponse (/root/api/topupapi/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/cjs/src/connection.js:790:26)
at handle (/root/api/topupapi/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/cjs/src/connection.js:476:6)
at Socket.data (/root/api/topupapi/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/cjs/src/connection.js:315:9)
at Socket.emit (node:events:517:28)
at addChunk (node:internal/streams/readable:368:12)
at readableAddChunk (node:internal/streams/readable:341:9)
at Socket.Readable.push (node:internal/streams/readable:278:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
[Nest] 1347376 - 01/14/2024, 8:55:05 PM ERROR [ExceptionsHandler] syntax error at or near "$1"
PostgresError: syntax error at or near "$1"
at ErrorResponse (/root/api/topupapi/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/cjs/src/connection.js:790:26)
at handle (/root/api/topupapi/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/cjs/src/connection.js:476:6)
at Socket.data (/root/api/topupapi/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/cjs/src/connection.js:315:9)
at Socket.emit (node:events:517:28)
at addChunk (node:internal/streams/readable:368:12)
at readableAddChunk (node:internal/streams/readable:341:9)
at Socket.Readable.push (node:internal/streams/readable:278:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
game is text (string) and checkCode is text (string) on this case provided as string[] when checkCode len is 1 we are getting this error but when its grater then 1 there aren't any error found
2 Replies
Angelelz
Angelelz11mo ago
inArray accepts an array or a subquery as the second argument, but it looks like you're passing a string Can you check if this would work?
const stock = await this.db.query.StockM.findMany({
where: (m, { inArray, eq, and }) =>
and(inArray(m.checkCode, [checkCode]), eq(m.game, game as Game)),
});
const stock = await this.db.query.StockM.findMany({
where: (m, { inArray, eq, and }) =>
and(inArray(m.checkCode, [checkCode]), eq(m.game, game as Game)),
});
ByteBender
ByteBenderOP11mo ago
CheckCode is type string[] actually I didn't name it CheckCodes I used class-validetor
Want results from more Discord servers?
Add your server