Skip to content

ERROR: function lower(bytea) does not exist during case-insensitive comparison on nullable string with JPQL LOWER #3928

Closed as not planned
@fnvir

Description

@fnvir

[BUG]
Given the entity:

public class Order {

    @Id
    @GeneratedValue(strategy = GenerationType.UUID)
    private UUID orderId;

    private UUID customerId;

    private String orderStatus;

    // getters and setters

The following JPQL query causes errors when using the LOWER function with strings on PostgreSQL.

    @Query("""
            SELECT
                o
            FROM
                Order o
            WHERE
                (:customerId IS NULL OR o.customerId = :customerId)
            AND
                (:status IS NULL OR LOWER(o.orderStatus) = LOWER(:status))
            """)
    Page<Order> findOrders(
            @Param("customerId") UUID customerId,
            @Param("status") String status,
            Pageable pageable
    );

It says:
Caused by: org.hibernate.exception.SQLGrammarException: JDBC exception executing SQL [select o1_0.order_id,o1_0.customer_id,o1_0.order_status from orders o1_0 where (? is null or o1_0.customer_id=?) and (? is null or lower(o1_0.order_status)=lower(?)) fetch first ? rows only] [ERROR: function lower(bytea) does not exist Hint: No function matches the given name and argument types. You might need to add explicit type casts.

Current workaround is to change the query to LOWER(o.orderStatus) = LOWER(COALESCE(:status, o.orderStatus))

Setup specs:
Spring Boot version : 3.5.3
PostgreSQL version: 17.5
Java: 21

Similar issue on stackoverflow with more details and explanation: https://stackoverflow.com/questions/77881433/org-postgresql-util-psqlexception-error-function-lowerbytea-does-not-exist

Github repository to replicate the issue

Metadata

Metadata

Assignees

Labels

status: invalidAn issue that we don't feel is valid

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions