honeysql 2023-11-07

I am trying to convert this PostgreSQL query into HoneySQL `SELECT` *types*.value ->> 'name' *AS* *`name`* *from* my_types mt, *jsonb_each*(mt.type_data -> 'types') *AS* *`types`* How can I write jsonb_each in honeysql?

Not familiar with -> and ->> in postgres but I think this gives you what you want

(-> (sqlh/select :types.value [[:raw "->> name"]] :name)
    (sqlh/from :mt_types [ [:jsonb_each :mt.type_data [:raw "-> types"]] :types])
    (sql/format))
;; => ["SELECT types.value, ->> name, name FROM mt_types, JSONB_EACH(mt.type_data, -> types) AS types"]

👍 1

Thank you, this is exactly what I want. I didn’t realize that jsonb_each is part of from :-).

yeah I did not notice at first, not written a postgres query like that before, but seemed an interesting challenge to test my honeysql knowledge 🙂

👏 1

Working query.. {:select [[[:->> :types.values "name"] "name"]] :from [[:my_types :mt] [:jsonb_each [[:-> :mt.type-data "types"] "types"]]] }

(to have support for :-> next.jdbc pg-opts must be loaded..

cool glad it helped :)