P
Prismaโ€ข4mo ago
Papa Smerf

Selecting random records from table

Hi! I would like to ask more experienced people for advice/ideas on how to use prisma to get random records from a table that meet some condition. I believe that fetching all the data from the table and then selecting random records is unnecessary and suboptimal. If anyone has an idea or knows how to achieve such an effect using prism, I would be grateful. ๐Ÿ˜„
3 Replies
Nurul
Nurulโ€ข4mo ago
Hey, this GitHub Discussion has a bunch of solutions you can use: https://github.com/prisma/prisma/discussions/5886
GitHub
How to get random recrods from findMany? ยท prisma prisma ยท Discussi...
As discussed in Prisma 1 forum, I'd like to know how to find random records in findMany. The below query should work in postgres. SELECT * FROM users ORDER BY random() LIMIT 1;
Alaskan donut
Alaskan donutโ€ข3mo ago
I'm really hoping Prisma will support random queries at some point... Here is an extension that achieves this: https://github.com/nkeil/prisma-extension-random. I haven't used this yet, but it's worth looking into.
Nurul
Nurulโ€ข3mo ago
Thanks for sharing the link to Prisma extension ๐Ÿ‘
Want results from more Discord servers?
Add your server