honeysql 2023-06-15

How could I generate this syntax? (Postgres array access subscript):

select eb.post_ids[1] from eb;

I'm interested mainly in tacking the [1] array subscript to any column in a select...

I'm surprised I can't find anything on it, anywhere. Also surprised that I have never had a need for it myself. I'd probably add a custom function/operator and make a PR for HoneySQL.

I'd be happy to add something like [:ix :col index-expr] => col[index-expr] but the name needs some consideration + tests + docs.

is :[] a valid clojure keyword, I wonder?

No, it's not 😄

The col must also be a col-expr

At least in my case, the I ended up doing

[:raw "(array_agg(timestamp))[1] as timestamp"]

I needed to also wrap the col-expr with parentheses

PG-related parts of HoneySQL use things like (def at> (keyword "@>")).

Good point about needing ( .. ) if you have a col-expr. Does PG allow (col)[1] or are parens only allowed for an expression there? (I never use PG so I've no idea how fussy it is)

initial testing shows that parenthesis are allowed everywhere, even for a single col

👍🏻 1

they are required for most everything else