Got a table in a postgres database with a jsonb column and needed to order a query using a specific key in the json as a numeric value, it is possible with native sql:
select key->>value from table where order by CAST(key->>value AS DECIMAL);
But with specification it is no possible directly, so I've encapsulate the operator CAST in a function and call it when building the order clause in the specification factory.
create or replace function cast_number(str varchar)
returns real
language plpgsql
as
$$
declare
new_number real;
begin
select cast(str as decimal)
into new_number;
return new_number;
end;
and I call it using CriteriaBuilder::function after calling jsonb_extract_path_text also via criteria builder. Still no sure about the performance here tbh
Did not found anything about this anywhere, so I want to share my solution and see what people think of it.