Back

[SOLVED] How to Query for Double Attribute

  • 0
  • Databases
  • Web
hosnipogi
20 Feb, 2023, 05:55

Hello, I have been trying to list documents containing the following query:

TypeScript
const min = (+val.minimum).toFixed(2) // ex. "51.23"
const max = (+val.maximum).toFixed(2) // ex. "82.12"

const result = await this.database.listDocuments(
  db.databaseId,
  Collection.IMAGES,
  [
    Query.greaterThanEqual("score", min),
    Query.lessThanEqual("score", max),
  ]
);```

but I keep getting the following response error:
```json
{
    "message": "Query not valid: Query type does not match expected: double",
    "code": 400,
    "type": "general_argument_invalid",
    "version": "1.2.0"
}```

the score attribute is a Float Attribute in the db
what is the correct way to query for double with appwrite?
TL;DR
The user is getting an error when trying to query for double attributes using Appwrite. They have been using a workaround for integers, but need help with doubles. Another user suggests removing the double quotes around the numbers. The original user provides raw and decoded payloads and mentions that the score attribute is a float attribute in the database. No solution is provided in the thread.
Drake
20 Feb, 2023, 06:36

Weird...this seems fine...are you able to see what's sent in the network request?

hosnipogi
20 Feb, 2023, 09:29

yup, here's what the raw payload looks like: queries%5B0%5D=greaterThanEqual%28%22score%22%2C+%5B%2251.23%22%5D%29&queries%5B1%5D=lessThanEqual%28%22score%22%2C+%5B%2292.12%22%5D%29&queries%5B2%5D=orderDesc%28%22score%22%29

heres how it looks decoded: queries[0]: greaterThanEqual("score", ["51.23"]) queries[1]: lessThanEqual("score", ["92.12"]) queries[2]: orderDesc("score")

hosnipogi
20 Feb, 2023, 09:30

seems like this is related to this issue: https://github.com/appwrite/appwrite/issues/4340

Drake
20 Feb, 2023, 15:26

That issue is for passing integers but you're passing decimal numbers

Drake
20 Feb, 2023, 15:26

Can you try to not use double quotes around the numbers?

hosnipogi
21 Feb, 2023, 03:24

this one worked lol, thank you!

hosnipogi
21 Feb, 2023, 03:26

but still for integers i would have to do a workaround like if the value is 50 - then i would just subtract 0.1 from it

hosnipogi
21 Feb, 2023, 03:26

[SOLVED] How to Query for Double Attribute

Drake
21 Feb, 2023, 03:28

Yes, hopefully, the fix will be in the next release

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more