Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Drizzle ORM · Function

inArray

inArray creates a Drizzle filter that checks whether a column matches one of several values. It accepts either an array or a subquery and produces an SQL IN condition.

How it works

Use inArray in a where clause to test whether a column matches one of several values. The second argument may be an array of values or a subquery selecting compatible values, and Drizzle emits the corresponding SQL IN condition.

Syntax

inArray(column, values)

Parameters

NameTypeDescription
columnColumnThe table column whose value is checked for membership.
valuesArray | Select queryAn array of compatible values or a subquery selecting compatible values.

Returns

A Drizzle SQL condition representing column membership in an array or subquery.

Key points

  • inArray expresses membership: a row matches when the specified column’s value occurs in the supplied collection.
  • Import the function from the top-level drizzle-orm package.
  • Use it directly as the predicate passed to a select query’s where method.
  • For a literal list, Drizzle generates an SQL IN predicate containing the supplied values.
  • A selecting query can provide the candidate values instead of an in-memory array.
  • When given a subquery, the resulting SQL compares the column against that subquery’s selected values.

Example: Filter rows by an array of values

import { inArray } from "drizzle-orm";
import { users } from "./schema";

const ids = [1, 2, 3];
const matchingUsers = await db
  .select()
  .from(users)
  .where(inArray(users.id, ids));

Builds a query that selects users whose IDs occur in the supplied array.

When to use it

Match a literal value list

Filter records against a known set of IDs, statuses, categories, or other values supplied by application code.

Match a subquery result

Filter one table using values selected from another query.

Interview questions

QWhat does inArray do?

inArray creates a filter for membership in a collection of values. For example, applying it to a column and [1, 2, 3, 4] produces an SQL IN predicate.

Follow-up: How can the candidate use a query instead of a literal list? Pass a subquery as the second argument; Drizzle produces an IN subquery condition.

QWhat forms can the second argument take?

Its first argument is the column being tested, and its second argument is either an array of candidate values or a selecting query. The selected values must be suitable for comparison with that column.

Follow-up: What SQL shape does a subquery form take? It becomes column IN (SELECT ...), with the selected expression supplying the comparison values.

QHow is inArray used in a Drizzle query?

The function is imported from drizzle-orm and is typically passed to where on a select, update, or delete query. This lets the database perform membership filtering rather than requiring separate application-side checks.

Follow-up: How would you filter using values returned from another table? Build a select query for the relevant column and pass that query as the second inArray argument.

  • notInArray
  • eq
  • and
  • or

Source: Filters - Drizzle ORM. Checked 2026-10-16.