import { kysely } from "https://deno.land/x/kysely_postgrs_js_dialect@v0.27.4/deps.ts";
const { AggregateFunctionBuilder } = kysely;
Adds a filter
clause with a nested where
clause after the function, where
both sides of the operator are references to columns.
Similar to WhereInterface's whereRef
method.
Examples
Count people with same first and last names versus general public:
const result = await db
.selectFrom('person')
.select((eb) => [
eb.fn
.count<number>('id')
.filterWhereRef('first_name', '=', 'last_name')
.as('repeat_name_count'),
eb.fn.count<number>('id').as('total_count'),
])
.executeTakeFirstOrThrow()
The generated SQL (PostgreSQL):
select
count("id") filter(where "first_name" = "last_name") as "repeat_name_count",
count("id") as "total_count"
from "person"
Type Parameters
LRE extends ReferenceExpression<DB, TB>
RRE extends ReferenceExpression<DB, TB>
Returns
AggregateFunctionBuilder<DB, TB, O>