Query wants a string when given an int, wants an int when given a string
See original GitHub issueBug description
With this query:
const areaId = '1';
const area = await db.area.findFirst({
where: {
id: areaId,
},
rejectOnNotFound: true,
})
model Area {
id String @id
type AreaType
treeCanopy Float
totalArea Float
}
When the areaId
variable is a string, I get
Invalid `prisma.area.findFirst()` invocation: Failed to validate the query: `Unable to match input value to any allowed input type for the field. Parse errors: [Query parsing/validation error at `Query.findFirstArea.where.AreaWhereInput.id`: Value types mismatch. Have: String("440030222021"), want: Object(IntFilter), Query parsing/validation error at `Query.findFirstArea.where.AreaWhereInput.id`: Value types mismatch. Have: String("440030222021"), want: Int]` at `Query.findFirstArea.where.AreaWhereInput.id`.
Okay, so let’s try an int. I change it to an int because it wants an int. Now, I get
Invalid `prisma.area.findFirst()` invocation: { where: { id: 440030222021 ~~~~~~~~~~~~ } } Argument id: Got invalid value 440030222021 on prisma.findFirstArea. Provided Int, expected StringFilter or String: type StringFilter { equals?: String in?: List<String> notIn?: List<String> lt?: String lte?: String gt?: String gte?: String contains?: String startsWith?: String endsWith?: String mode?: QueryMode not?: String | NestedStringFilter } type StringFilter { equals?: String in?: List<String> notIn?: List<String> lt?: String lte?: String gt?: String gte?: String contains?: String startsWith?: String endsWith?: String mode?: QueryMode not?: String | NestedStringFilter } .
So: when I have a string input to a query, it wants an int. When I have an int input, it wants a string. Frustrating.
How to reproduce
- Load the given schema
- Try the given query
Expected behavior
A string should be the input here.
Prisma information
- Prisma/client 3.9.2
- prisma 3.9.2
Environment & setup
- OS: macOS
- Database:PostgreSQL
- Node.js version: 14.x
Prisma Version
3.9.2
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Searching an int column on the basis of a string value
The query you have provided need to be optimized: First, using CAST(bkID AS NVARCHAR(MAX)) will affect the performance of the query, ...
Read more >SQL Substring function overview - SQLShack
The T-SQL SUBSTRING function is very useful when you want to make sure that the string values returned from a query will be...
Read more >Given two strings, find if first string is a Subsequence of second
The idea is simple, traverse both strings from one side to another side (say from rightmost character to leftmost). If we find a...
Read more >i want to convert string into integer - Oracle Communities
This usually means that the given string is not in numeric format. What is it's value?
Read more >Reference guide for expression functions - Azure Logic Apps
Given that the result is an object with property propertyName, get that property's value. ... int, Return the integer version for a string....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This bug report includes the schema. The
id
column is a string column. If the column as an Int, then I would expect this to work with an integer value. As the issue describes, the query does not work with either integer or string values, and for each it requests the other.Could it be that
id
used to be anInt
and somehow the schema used by the engine and the client are out of sync? Maybe a missingnpx prisma generate
or database migration?