ORDER BY in agg function.

Hi, I would like to represent something like
json_agg(table ORDER BY column) as values
json_agg(table ORDER BY column) as values
in kysely. How would I go about doing this? Thanks in advance.
2 Replies
Igal
Igal•14mo ago
Hey 👋
import { sql } from 'kysely'

// ...

.select(sql<Type>`json_agg(table order by column)`.as("values"))
import { sql } from 'kysely'

// ...

.select(sql<Type>`json_agg(table order by column)`.as("values"))
We don't have built-in support for json_agg, eb.table (unreleased probably) or order by of a table ref. So this is the best approach right now imho. Can you provide docs link of this SQL syntax?
Alexander Dennis Enviro 200XLB
Thank you, I am currently using sql but I did not realise you could pass a type argument! I found this in the postgres docs: https://www.postgresql.org/docs/current/sql-expressions.html#SYNTAX-AGGREGATES
PostgreSQL Documentation
4.2. Value Expressions
4.2. Value Expressions # 4.2.1. Column References 4.2.2. Positional Parameters 4.2.3. Subscripts 4.2.4. Field Selection 4.2.5. Operator Invocations 4.2.6. Function Calls …
Want results from more Discord servers?
Add your server