I have a table named loans with a lot of fields such as (id, name, description, etc.) And inside that table, I have a column which type is JSON(TermsMessage)(ARRAY OF JSON), and when I make a select query it returns me an error
my query
`
select
z.loan_id,
z.loan_name,
z.max_amount,
z.min_amount,
z.min_age,
z.max_age,
z.min_loan_term,
z.max_loan_term,
z.TermsMessage,
to_json(array_agg(distinct z.jsjs)) as aims,
to_json(array_agg(distinct z.jsjs1)) as cities,
from(
select
c.loan_id,
c.loan_name,
c.max_amount,
c.min_amount,
c.min_age,
c.max_age,
c.min_loan_term,
c.max_loan_term,
c.TermsMessage,
( select x from (select c.aim_id, c.aim_name) x) as jsjs,
( select x from (select c.city_id, c.city_name) x) as jsjs1
from
( select
l.id as loan_id,
l.name as loan_name,
l.max_amount,
l.min_amount,
l.min_age,
l.max_age,
l.min_loan_term,
l.max_loan_term,
l.TermsMessage,
--
a.id as aim_id,
a.name as aim_name,
--
c.id as city_id,
c.name as city_name
--
from loans as l
left join loan_aims as la on la._loan = l.id
left join aims as a on a.id = la._aim
------------
left join loan_cities as lc on lc._loan=l.id
left join cities as c on c.id = lc._city
------------
) c
) z
group by z.loan_id,
z.loan_name,
z.max_amount,
z.min_amount,
z.min_age,
z.max_age,
z.min_loan_term,
z.max_loan_term;
`
termsMessage must appear in the GROUP BY clause or be used in an aggregate function
and when I add json column into GROUP BY it return an another error
group by z.loan_id,
z.loan_name,
z.max_amount,
z.min_amount,
z.min_age,
z.max_age,
z.min_loan_term,
z.max_loan_term,
z.TermsMessage;
could not identify an equality operator for type json