Raw query failed. Code: `42601`. Message: `db error: ERROR: syntax error at or near "$1"` Postgresql INTERVAL
See original GitHub issueBug description
const time = 5
await this.prisma.$executeRaw`
UPDATE public.user SET chat_banned_time = NOW() + INTERVAL '${time} MINUTES' WHERE id = ${userId}
`;
PrismaClientKnownRequestError:
Invalid `prisma.executeRaw()` invocation:
Raw query failed. Code: `42601`. Message: `db error: ERROR: syntax error at or near "$1"`
at Object.request (C:\disapp\api\node_modules\@prisma\client\runtime\index.js:45629:15)
at async Proxy._request (C:\disapp\api\node_modules\@prisma\client\runtime\index.js:46456:18)
at async Service.handler (C:\disapp\api\services\player\chat\chat.service.js:581:22)
at async Service.callAction (C:\disapp\api\node_modules\moleculer-web\src\index.js:636:16)
at async C:\disapp\api\node_modules\moleculer-web\src\index.js:461:22 {
code: 'P2010',
clientVersion: '3.13.0',
meta: {
code: '42601',
message: 'db error: ERROR: syntax error at or near "$1"'
}
}
How to reproduce
const time = 5
await this.prisma.$executeRaw`
UPDATE public.user SET chat_banned_time = NOW() + INTERVAL '${time} MINUTES' WHERE id = ${userId}
`;
Expected behavior
No response
Prisma information
model User {
id Int @id @default(autoincrement())
chatBannedTime DateTime? @map("chat_banned_time")
}
Environment & setup
- OS:
- Database:
- Node.js version:
Prisma Version
"prisma": "^3.13.0"
Issue Analytics
- State:
- Created a year ago
- Reactions:7
- Comments:9 (3 by maintainers)
Top Results From Across the Web
PostgreSQL error 42601- How we fix it
PostgreSQL error 42601 mainly occurs due to the syntax errors in the code. Proper syntax check and code correction will fix it up....
Read more >Using CASE for both field and order sorting in an ORDER ...
queryRaw()` invocation:\n\n\n Raw query failed. Code: `42601`. Message: `db error: ERROR: syntax error at or near \"CASE\"`",.
Read more >Documentation: 8.1: PostgreSQL Error Codes
Error Code Meaning Constant
00000 SUCCESSFUL COMPLETION successful_completion
01000 WARNING warning
0100C DYNAMIC RESULT SETS RETURNED dynamic_result_sets_returned
Read more >Troubleshooting queries in Amazon Redshift Spectrum
After five failed retries, the query fails with the following error. Large file sizes (greater than 1 GB). Check your file sizes in...
Read more >SQL Error [42601]: ERROR: syntax error at or near "limit"
LIMIT isn't a valid keyword in an UPDATE statement according to the official PostgreSQL documentation: [ WITH [ RECURSIVE ] with_query [, ....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I am unfortunately not able to do that in next few days. Anyhow it would not be the query I would have to share, but the generation using template strings. Queries are generated, by a function. Table names are dynamically added and some conditions based on functions params will be added.
Though, it is now working with
prisma.$rawQuery
and actually that is totally fine. My queries are for calculating statistics and filling other tables. None of the params are changeable by any user.Same for you then @patrickJramos: