honeysql

orestis 2023-06-15T07:48:43.289579Z

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

select eb.post_ids[1] from eb;

orestis 2023-06-15T07:49:14.243159Z

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

p-himik 2023-06-15T08:53:40.706879Z

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.

seancorfield 2023-06-15T14:59:54.371249Z

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

orestis 2023-06-15T17:22:47.773659Z

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

orestis 2023-06-15T17:24:15.724219Z

No, it's not 😄

orestis 2023-06-15T17:24:56.675799Z

The col must also be a col-expr

orestis 2023-06-15T17:25:33.555159Z

At least in my case, the I ended up doing

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

orestis 2023-06-15T17:25:45.774779Z

I needed to also wrap the col-expr with parentheses

p-himik 2023-06-15T17:25:47.846909Z

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

seancorfield 2023-06-15T18:12:40.071079Z

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)

orestis 2023-06-15T18:26:17.736409Z

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

👍🏻 1
orestis 2023-06-15T18:26:23.511569Z

they are required for most everything else