Module

x/kysely_postgrs_js_dialect/mod.ts>kysely.WheneableMergeQueryBuilder#whenNotMatchedAnd

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

Adds the when not matched clause to the query with an and condition.

This method is similar to {@link SelectQueryBuilder.where}, so see the documentation for that method for more examples.

For a simple when not matched clause (without an and condition) see {@link whenNotMatched}.

Unlike {@link whenMatchedAnd}, you cannot reference columns from the table merged into.

Examples

const result = await db.mergeInto('person')
  .using('pet', 'person.id', 'pet.owner_id')
  .whenNotMatchedAnd('pet.name', '=', 'Lucky')
  .thenInsertValues({
    first_name: 'John',
    last_name: 'Doe',
  })
  .execute()

The generated SQL (PostgreSQL):

merge into "person"
using "pet" on "person"."id" = "pet"."owner_id"
when not matched and "pet"."name" = $1 then
  insert ("first_name", "last_name") values ($2, $3)