spring-attic / spring-cloud-gcp

Integration for Google Cloud Platform APIs with Spring
Apache License 2.0
704 stars 694 forks source link

Not Equal in the @Query #2608

Closed beunick closed 3 years ago

beunick commented 3 years ago

Hi, I am trying to use NOT EQUAL in my query but I still getting error and don't know how to solve it. Here is a sample code:

@Query("select * from product where id != @product_key and code = @product_code")
Product existsByCode(@Param("product_code")String code, @Param("product_key")Key key);

Here is the error: "Lexical error at line 1, column 32. Encountered: \"!\" (33), after : \"\"",

How to use Not Equal in my sql query (@Query) for datastore ?

Please let me know. Thank You.

dmitry-s commented 3 years ago

Hi @beunick,

Cloud Datastore doesn't support !=. Please see https://cloud.google.com/datastore/docs/reference/gql_reference#operators_and_comparisons for the list of supported comparators.

You might need to run two queries (one for id > @product_key and another one for id < @product_key) and combine results.

Thanks