Skip to content

Introduce abstractions to define custom criteria predicates #1953

Open
0 of 1 issue completed
Open
@Wuzhengyu97

Description

@Wuzhengyu97

I am using Spring Data R2DBC with a PostgreSQL database. My goal was to use CriteriaDefinition to describe a query for a column of type text[] in PostgreSQL. Specifically, I wanted to perform array-related operations such as checking if the array contains a value (using the PostgreSQL @> operator).

For example, I expected to write something like this:

Query.query(Criteria.where("tags").contains("electronics"));

However, I could not find any built-in support for such array operators in CriteriaDefinition. This left me wondering if I have missed some part of the documentation or if this functionality is not supported.

The lack of array operator support means that for now, I would have to resort to raw SQL for such queries, like this:

String sql = "SELECT * FROM products WHERE tags @> ARRAY['electronics']::text[]";
databaseClient.sql(sql).all();

This feels frustrating, especially because I want to leverage the abstraction of R2dbcEntityTemplate and avoid writing raw SQL. Is there currently a way to describe such queries using CriteriaDefinition, or are array-related operations not yet supported for PostgreSQL?

I would greatly appreciate any insights or guidance on this topic.

Sub-issues

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions