Re: coalesce(json_agg [..] filter where [..], '[]' in left join returning null

Поиск
Список
Период
Сортировка
От Stefan Houtzager
Тема Re: coalesce(json_agg [..] filter where [..], '[]' in left join returning null
Дата
Msg-id CANJtTDn2+CNTASDBFK=Y8pAdD6RKMP0X2eGspMcZ7U-H9qu9Rw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: coalesce(json_agg [..] filter where [..], '[]' in left join returning null  ("David G. Johnston" <david.g.johnston@gmail.com>)
Ответы Re: coalesce(json_agg [..] filter where [..], '[]' in left join returning null  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-novice
Thanks again David. I am very novice, and tried the following which does not give an error but returns null instead of []
select
         json_agg(
         (select row_to_json(_) from
                  (select vc.id, vc.descr, vc.expense, vc.version, vat_percentage) as _
              )    
         )    
        from vat_cat vc
        left join (
            select
                vatcat_id,
                COALESCE(NULLIF(
                  json_agg(
                        (select row_to_json(_) from
                            (select vp.percentage, vp.version, json_build_object(
                                'lower', lower(vp.validity),
                                'upper', upper(vp.validity),
                                'lower_inc', lower_inc(vp.validity),
                                'upper_inc', upper_inc(vp.validity)
                            ) validity)
                          as _)
                  )::text,
                'null'::text), '[]'::text) vat_percentage
            from vat_percentage vp
            group by vatcat_id

        ) vp on vc.id = vp.vatcat_id

On Wed, Jan 6, 2021 at 5:10 PM David G. Johnston <david.g.johnston@gmail.com> wrote:
On Wed, Jan 6, 2021 at 8:59 AM Stefan Houtzager <stefan.houtzager@gmail.com> wrote:

ERROR: operator does not exist: json = json LINE 11: COALESCE(NULLIF( ^ HINT: No operator matches the given name and argument types. You might need to add explicit type casts. SQL state: 42883 Character: 306  


Right, json doesn't implement equality.  You will need to cast to and compare text values.

David J.



--
Kind regards,

Stefan Houtzager

Houtzager ICT consultancy & development

www.linkedin.com/in/stefanhoutzager

В списке pgsql-novice по дате отправления:

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: Understanding aggregation and window functions.
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: coalesce(json_agg [..] filter where [..], '[]' in left join returning null