-2
I have this query where I try to do an Insert through the main query, but I believe that on account of json_array_legth() it does not let me insert presenting the following error: SQL Error [22023]: ERROR: cannot get array length of a scalar
with p as (
select
ft_decision_motor.dt_create,
ft_decision_motor.id_trx,
ft_decision_motor.response,
ft_decision_motor.response->>'text' 5,
(lower(ft_decision_motor.response ->> 'text') ~~ 'text%') as 4,
((ft_decision_motor.response -> 'text') ? 'text') as 3,
(lower(ft_decision_motor.response ->> 'text') ~~ '%text%') as 2,
((ft_decision_motor.response -> 'text') ? 'text.') as 1,
jsonb_array_length(response->'text') as Outros
from
bi.ft_decision_motor where response ? 'text' is not null)
insert into kde.reasons_am
select
p.column1,
p.column2,
p.column3,
p.column4,
p.column5,
p.column6,
p.column7,
p.Outros
from p where Outros >= 1
order by dt_create desc;