Module

x/kysely_postgrs_js_dialect/deps.ts>kysely.DeleteQueryBuilder#whereRef

Kysely dialect for PostgreSQL using the Postgres.js client.
method kysely.DeleteQueryBuilder.prototype.whereRef
import { kysely } from "https://dotland.deno.dev/x/kysely_postgrs_js_dialect@v0.27.3/deps.ts";
const { DeleteQueryBuilder } = kysely;

Adds a where clause where both sides of the operator are references to columns.

The normal where method treats the right hand side argument as a value by default. whereRef treats it as a column reference. This method is expecially useful with joins and correlated subqueries.

Examples

Usage with a join:

db.selectFrom(['person', 'pet'])
  .selectAll()
  .whereRef('person.first_name', '=', 'pet.name')

The generated SQL (PostgreSQL):

select * from "person", "pet" where "person"."first_name" = "pet"."name"

Usage in a subquery:

const persons = await db
  .selectFrom('person')
  .selectAll('person')
  .select((eb) => eb
    .selectFrom('pet')
    .select('name')
    .whereRef('pet.owner_id', '=', 'person.id')
    .limit(1)
    .as('pet_name')
  )
  .execute()

The generated SQL (PostgreSQL):

select "person".*, (
  select "name"
  from "pet"
  where "pet"."owner_id" = "person"."id"
  limit $1
) as "pet_name"
from "person"

Type Parameters

LRE extends ReferenceExpression<DB, TB>
RRE extends ReferenceExpression<DB, TB>