question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Raw query failed. Code: `42601`. Message: `db error: ERROR: syntax error at or near "$1"` Postgresql INTERVAL

See original GitHub issue

Bug 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:closed
  • Created a year ago
  • Reactions:7
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kivicommented, Sep 15, 2022

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.

0reactions
janpiocommented, Sep 19, 2022

Same for you then @patrickJramos:

Optimally open a new issue and provide all the information the bug issue template is asking for.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found