honeysql

Akiz 2025-03-14T16:26:54.637379Z

Hi, does honeysql have syntax for Postgresql ROW_NUMBER() OVER (….) ?

Akiz 2025-03-14T16:31:33.152649Z

(hsql/format {:select [[[(keyword "row_number() over") "D"]]] :from :a}) => [“SELECT ROW_NUMBER() OVER(?) FROM a” “D”] There must be a better way, right? 😅

seancorfield 2025-03-14T16:50:58.575929Z

Is this close to what you want:

user=> (hsql/format {:select [[[:over [[:row_number] {:select [["D" :d]]}]]]] :from :a})
["SELECT ROW_NUMBER() OVER (SELECT ? AS d) FROM a" "D"]

Akiz 2025-03-14T16:52:31.759799Z

Yes, I just found it in the documentation. I didn’t think to look for it there if I didn’t find the question about it on slack. My mistake and thanks!

Akiz 2025-03-14T16:53:30.577489Z

Actually - why would anyone ask if they look at the documentation first 😅

seancorfield 2025-03-14T16:57:07.536379Z

There's a lot of documentation. Folks often miss something or other.

Akiz 2025-03-14T17:05:20.182509Z

I would also like to ask about this one.. 🙏 jsonb_path_query_array(abcd, '$."z-x-c".types.*.values.*."id"') @> '["ea1a9af7-94ec-49cc-af44-221adf46bf6f", ....]' I construct it like this

[:jsonb_path_query_array
:abcd
[:raw "'$.\"z-x-c\".types.*.values.*.\"id\"'"]]
[:raw (format "'[%s]'" (str/join ","  (map #(str "\"" % "\"") ids)))]]
The first :raw is fine, I don’t need to construct it in HoneySQL. But what about the array in single quotes, is there some syntax for it?

seancorfield 2025-03-14T17:07:32.950139Z

I'd use :inline instead of :raw since it will turn "fo\"o" into 'fo"o' so you don't need the single quotes in there.

seancorfield 2025-03-14T17:12:18.196569Z

The main issue here is that you're dealing with strings in SQL -- '...' -- rather than "syntax", so there's not much HoneySQL can do to help.

Akiz 2025-03-14T17:16:31.740269Z

Right, no problem, thank you.