Fork me on GitHub
#honeysql
<
2021-06-22
>
Eric Casteleijn20:06:36

Is there a way to express array_agg(distinct table.field) in honeysql, specifically the distinct there, or do I have to fall back to raw in that case?

seancorfield20:06:34

@thisfred If you’re using 2.0.0 RC 3, you can do it like this:

dev=> (sql/format-expr [:array_agg [:distinct :table/field]])
["ARRAY_AGG(DISTINCT table.field)"]

Eric Casteleijn20:06:52

Thank you so much!

seancorfield20:06:24

Or like this in a select:

dev=> (sql/format {:select [ [ [:array_agg [:distinct :table/field]] :agg ] ] :from :table})
["SELECT ARRAY_AGG(DISTINCT table.field) AS agg FROM table"]

Eric Casteleijn20:06:27

I don’t think we’re on that yet, but I’ll make a note to replace the raw with that as soon as we upgrade