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 doesn't return data if query doesn't start with SELECT statement

See original GitHub issue

I’m using the Prisma Beta2 with Postgres and prisma.raw and am getting a panic error when trying to do a recursive query.

I have the following schema

model Task {
  id String @default(cuid()) @ id
  parent Task? @relation("TaskTree", fields: [parentId], references: [id])
  parentId String?
  children Task[]  @relation("TaskTree")
}

I need to get all descendants of a given node referenced via it’s id. The following sql gets me the results I need. It works perfectly fine in postgres.

          WITH RECURSIVE descendants AS (
              SELECT *
              FROM "Task"
              WHERE id = '${id}'
          UNION ALL
              SELECT t.*
              FROM "Task" t
              JOIN descendants ON t."parentId" = descendants.id
          )
          SELECT * FROM descendants;

However, when I plug it into prisma.raw I get the Error: PANIC: expected 0 parameters but got 1

Here’s my error logs:

  plusX Execution permissions of /Users/ryanking/Documents/Projects/cc_gantt_server_prod/node_modules/@prisma/client/runtime/query-engine-darwin are fine +0ms
  engine { flags: [ '--enable-raw-queries' ] } +1ms
  engine stderr Printing to stderr for debugging +146ms
  engine stderr Listening on 127.0.0.1:64177 +1ms
  engine stdout { timestamp: 'Apr 16 11:41:01.870',
  level: 'INFO',
  target: 'quaint::pooled',
  fields:
   { message: 'Starting a postgresql pool with 5 connections.' } } +36ms
  engine stdout { timestamp: 'Apr 16 11:41:01.910',
  level: 'INFO',
  target: 'query_engine::server',
  fields:
   { message: 'Started http server on 127.0.0.1:64177',
     'log.target': 'query_engine::server',
     'log.module_path': 'query_engine::server',
     'log.file': 'query-engine/query-engine/src/server.rs',
     'log.line': 109 } } +34ms
  engine stdout { timestamp: 'Apr 16 11:41:02.094',
  level: 'ERROR',
  target: 'query_engine',
  fields:
   { message: 'PANIC',
     reason: 'expected 0 parameters but got 1',
     file: '<::std::macros::panic macros>',
     line: 5,
     column: 6 } } +183ms
  engine { error:
  engine    { Error: socket hang up
  engine        at createHangUpError (_http_client.js:323:15)
  engine        at Socket.socketOnEnd (_http_client.js:426:23)
  engine        at Socket.emit (events.js:194:15)
  engine        at endReadableNT (_stream_readable.js:1125:12)
  engine        at process._tickCallback (internal/process/next_tick.js:63:19) code: 'ECONNRESET' } } +6ms
Error: PANIC: expected 0 parameters but got 1
    at PrismaClientFetcher.request (/Users/ryanking/Documents/Projects/cc_gantt_server_prod/node_modules/@prisma/client/runtime/index.js:1:53048)
    at process._tickCallback (internal/process/next_tick.js:68:7)
Error in Prisma Client:
PANIC: expected 0 parameters but got 1 in
<::std::macros::panic macros>:5:6

Am I also correct in assuming this query can’t be done with graphql?


Edit: The same query is working fine with https://node-postgres.com/

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
albertoperdomocommented, Jun 2, 2020

We’ve decided to go ahead and deprecate raw in favor of these two separate methods (one for query, another for execute) as suggested by @pimeys.

Naming of the two methods is still TBD.

4reactions
albertoperdomocommented, Jun 3, 2020

Update:

  • naming: we’ve decided to go with queryRaw and executeRaw.
  • existing raw method: will be removed in favor of these two new dedicated methods.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Sql raw query doesn't works properly - Stack Overflow
I am using an except clause on my query, But however I get an error as below: The text format of the query...
Read more >
Performing raw SQL queries | Django documentation
raw () . Django expects that the statement will return a set of rows from the database, but does nothing to enforce that....
Read more >
Raw database access (Reference) - Prisma
Learn how you can send raw SQL and MongoDB queries to your database using the raw() methods from the Prisma Client API.
Read more >
Raw Queries - Sequelize
In case of false it will return all records. plain: false, // Set this to true if you don't have a model definition...
Read more >
SQL Queries - EF Core - Microsoft Learn
SQL queries are useful if the query you want can't be expressed using LINQ ... SQL queries can return regular entity types or...
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