1

Using the ":" as delimeter to split the timings from the date. Its works when we run a query in sql. When it comes with JPA, jpa considered this ":" delimeter as named parameter, how to overcome this issue.

Query:

select (case when SPLIT_PART(
                     SPLIT_PART(inq.suggest_time::text, ' ', 2),
                     ':', 1
                  )::int <= 10 and
                  SPLIT_PART(
                     SPLIT_PART(inq.suggest_time::text, ' ', 2),
                     ':', 2
                  )::int < 30
             then CONCAT(
                     (SPLIT_PART(
                         SPLIT_PART(inq.suggest_time::text, ' ', 1),
                         '-', 1
                     )::int)::text,
                     '-',
                     (SPLIT_PART(
                         SPLIT_PART(inq.suggest_time::text, ' ', 1),
                         '-', 2
                     )::int)::text,
                     '-',
                     (SPLIT_PART(
                         SPLIT_PART(inq.suggest_time::text, ' ', 1),
                         '-', 3
                     )::int + 1)::text)
             else (SPLIT_PART(inq.suggest_time::text, ' ', 1))::text
             end) as dateValue,
       count(inq.suggest_time )
from inquiry_table inq
where inq.assigned_to= 63
  and (inq.suggest_time is not null)
  and inq.inquiry_status IN (select ld.lookup_detail_id
                             from lookup_detail ld
                             where ld.lookup_detail IN ('New','In Process'))
group by dateValue
ORDER BY dateValue;

Error in app:

Caused by: org.springframework.web.util.NestedServletException: Request processing failed;
nested exception is org.hibernate.QueryException: Not all named parameters have been set: [:text, :int] [select (case when SPLIT_PART(SPLIT_PART(inq.suggest_time::text, ' ', 2), ':', 1)::int <= 10 and SPLIT_PART(SPLIT_PART(inq.suggest_time::text, ' ', 2), ':', 2)::int < 30 then CONCAT((SPLIT_PART(SPLIT_PART(inq.suggest_time::text, ' ', 1), '-', 1)::int)::text, '-',(SPLIT_PART(SPLIT_PART(inq.suggest_time::text, ' ', 1), '-', 2)::int)::text, '-',(SPLIT_PART(SPLIT_PART(inq.suggest_time::text, ' ', 1), '-', 3)::int + 1)::text) else (SPLIT_PART(inq.suggest_time::text, ' ', 1))::text end) as dateValue,count(inq.suggest_time )  from inquiry inq where inq.assigned_to= 63 and (inq.suggest_time is not null) and inq.inquiry_status IN (select ld.lookup_detail_id from lookup_detail ld where ld.lookup_detail IN ('New','In Process')) group by dateValue ORDER BY dateValue]
Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
Pearl
  • 384
  • 1
  • 8
  • 15
  • 1
    It's most probably the cast `::text` or `::int` not the delimiter. Try changing that to e.g. `cast (inq.suggest_time as text)` to make your obfuscation layer happy –  Nov 25 '20 at 07:43
  • 2
    Unrelated to your problem, but the `split_part()` monster looks horrible. What exactly are you trying to do there? I am pretty sure there are better ways to format a `time` value then that. –  Nov 25 '20 at 07:53
  • 1
    Did you try escaping the colon with a backslash? – Laurenz Albe Nov 25 '20 at 07:54
  • Thanks all... I tried colon with backslash. It's working fine. Yes query seems messy. Will try to simplify it. – Pearl Nov 25 '20 at 11:07

1 Answers1

1

Escape the :: in ::text & ::int as shown below:

\\:\\:text
\\:\\:int

Refer: https://stackoverflow.com/a/29161044/6294804

Rajib Biswas
  • 772
  • 10
  • 27