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.

No results when using cursor and orderBy (Text type)

See original GitHub issue

Bug description

When using findMany I encountered a bug where the logged query from prisma returns data, yet the findMany result does not. I narrowed the bug down to using cursor+orderBy (text column) … strangely enough, when orderBy is of BigInt type, it seems to work

How to reproduce

  1. Clone this repo https://github.com/redeyecz/prisma-bug
  2. docker-compose up
  3. http://localhost:3000
  4. The shown output prints all database records in the test database, example of cursor+orderBy (bigInt), failed result of cursor+orderBy (text) and expected result

Expected behavior

I’d expect to get the data from findMany, that the database query returns

Prisma information

model Account {
  id         BigInt   @id @default(autoincrement())
  name       String?
  externalId String?
  type       String
  dateInsert DateTime @default(now())

  @@unique([type, externalId])
  @@map("account")
}
prisma.account.findMany({
    take: 3,
    skip: 1,
    cursor: {
      id: 9 //Test3
    },
    orderBy: {
      externalId: 'desc' // text column
    }
  })

Environment & setup

Node 14.16

  • OS: Windows running WSL2, Docker-engine running Debian 10 (buster) based linux
  • Database: Postgres 13.2 (Docker based on alpine image)
  • Node.js version: v14.16.0
  • Prisma version: 2.20.1
prisma               : 2.20.1
@prisma/client       : 2.20.1
Current platform     : debian-openssl-1.1.x
Query Engine         : query-engine 60ba6551f29b17d7d6ce479e5733c70d9c00860e (at node_modules/@prisma/engines/query-engine-debian-openssl-1.1.x)
Migration Engine     : migration-engine-cli 60ba6551f29b17d7d6ce479e5733c70d9c00860e (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine : introspection-core 60ba6551f29b17d7d6ce479e5733c70d9c00860e (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary        : prisma-fmt 60ba6551f29b17d7d6ce479e5733c70d9c00860e (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash : 60ba6551f29b17d7d6ce479e5733c70d9c00860e
Studio               : 0.365.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
pantharshit00commented, Apr 12, 2021

Thanks for extremely detailed reproduction @redeyecz and also @hehex9

I can confirm this. We will patch this.

1reaction
hehex9commented, Apr 12, 2021

my minimal and reproducible example: https://github.com/hehex9/prisma-6337

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why an cursor opened for a select with ORDER by does ...
SQL Server implicitly converts the cursor to another type if clauses in select_statement conflict with the functionality of the requested cursor ...
Read more >
order by not working in implicit cursor
I have a function I'm using to pipe out rows. However the order of the result set does not change when I pass...
Read more >
SQL Order by Clause overview and examples
This article will cover the SQL ORDER BY clause including syntax, usage scenarios to sort out results in a Select statement.
Read more >
Sort records on text, numeric, or date values
The last-applied sort order is automatically saved with the table, query, form, or report. If you want it automatically applied the next time...
Read more >
Pagination of Results | Apache Solr Reference Guide 8.7
Pagination using start and rows not only require Solr to compute (and sort) ... Cursor mark values are computed based on the sort...
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