-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scalar array query missing order clause #930
Scalar array query missing order clause #930
Comments
@brett-nuske-alliancesoftware : Thanks for reaching out 🙏 I think that you found a bug there but the analysis and your suggestion is not entirely correct. Here a few observations:
|
I just compared the implementations of Prisma 1 and Prisma 2. We indeed added the suggested order by clause for |
So for the ordering of Scalar lists, you should handle that on the application level. Scalar lists are returned on the order they are stored which is persisted by us. You can also store them as a relationship if you want for complex ordering directly via the database. |
@pantharshit00 I was not looking for complex ordering. If I stored a String[] that contained ['A', 'B', 'C'] I would expect that to be returned in that order. This is not happening because the database is returning an arbitrary result set ordering as there is no order clause in the generated sql query. |
This is kind of obvious from the code where the order should be but is not. Although I still haven't been able to write a test where I could see the problem. That takes a bit more time than the fix which is two lines of code... |
Ok, tested this with the following: Model model User {
id String @default(cuid()) @id
email String @unique
name String?
skills String[]
} Mutation mutation {
createOneUser(data: {
email: "foo@bar.com"
skills: { set: ["cats", "dogs", "mice", "elephants"] }
}) { id }
} First query query {
findOneUser(where: { id: "ck3eefbgd0000xhjiaepsz20k" }) {
skills
}
} The values are in the right order. Now going to Postgres and deleting the The fix I merged now to master will fix this. |
I have a model:
When executing:
I notice in my PostgreSQL logs that the one of the queries that is executed is as follows:
Unfortunately the result of this query is not ordered and therefore the results for
name
are inconsistent. What I am experiencing is that if the results are as follows:Then name for
ck2v8nuom000145r0p7c0gti4
is['C']
instead of['B', 'C']
.My proposal is that the generated query should be:
The text was updated successfully, but these errors were encountered: