Skip to content

Order By named parameter #805

Closed as not planned
Closed as not planned
@engilyin

Description

@engilyin

I can't set the query order using the named parameter like

@Query("""
    SELECT * 
    FROM mytable
    ORDER BY :orderParam
    OFFSET :offset LIMIT :limit
""")
public Flux<MyObject> findObjects(@Param("orderParam") String orderParam, 
            @Param("offset") long offset,
            @Param("limit") long limit);

If I call:

var objects = repo.findObjects("fieldname DESC", 0, 100);

It works but using default order.

That happens because this parameter is wrapped with single quotas as a SQL string literal:

    SELECT * 
    FROM mytable
    ORDER BY 'fieldname DESC'
    OFFSET 0 LIMIT 100

Also you can find similar request at:
https://stackoverflow.com/questions/74111689/r2dbc-querying-from-multiple-tables-with-sorting-and-pagination/74756531#74756531

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions