Support query for random row(s)
See original GitHub issueProblem
In Prisma 1 there was conversation around potentially including a way to query for a random row(s) in the database. See https://github.com/prisma/prisma1/issues/114. I think this should still be considered in Prisma 2 (and don’t want the feature request to get lost in the transition to this new repo).
Without this feature, in order to do random lookup of the table you would first need make a call for the count of the number of rows in a table. Then create a random number bounded by that count. And make another call to find that row. I think prisma has the potential to make this feature usable and performant.
Suggested solution
In the linked issue (https://github.com/prisma/prisma1/issues/114) the discussion lead to utilizing the orderBy
with a random
option seems to make the most sense. But, maybe that random
option should only be available to id fields as to not make it confusing.
Also, how this is solved in the Engine I’m less sure. As each database can solve this differently and probably some queries are more/less performant than others.
Alternatives
Would love some more conversation around this.
Additional context
Again think prisma is well poised to make this a usable performant feature. Because doing it in sql is very database dependent and very non-performant if you aren’t careful. See this discussion: https://stackoverflow.com/questions/19412/how-to-request-a-random-row-in-sql
Issue Analytics
- State:
- Created 3 years ago
- Reactions:25
- Comments:6
+1
+1