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

Drizzle ORM · Function

gt

gt builds a greater-than filter for Drizzle queries. It compares a column or SQL expression with a value or another expression and is typically passed to where.

How it works

gt creates a filter that compares a column or SQL expression with a value or another column and keeps rows where the left side is greater. Use it inside a query's where clause; Drizzle emits the SQL > comparison and parameterizes supplied values.

Syntax

gt(left, right)

Parameters

NameTypeDescription
leftSQL expressionLeft-hand column or SQL expression to compare.
rightvalue or SQL expressionValue or column/expression that the left operand must exceed.

Returns

A SQL boolean condition for use in query filters.

Key points

  • Keeps rows where the first operand is greater than the second operand.
  • The operator is available as a named import from the drizzle-orm package.
  • A scalar comparison becomes a SQL > predicate in the generated statement.
  • The operands may be two columns, enabling row filtering based on column-to-column comparison.

Common mistakes

  • Values passed to gt are parameterized automatically, so use the operator instead of interpolating runtime values into SQL.

Example: Filter rows with gt

import { gt } from "drizzle-orm";

const rows = await db
  .select()
  .from(users)
  .where(gt(users.age, 18));

Selects users whose age is greater than 18.

When to use it

Threshold filtering

Filter records above a threshold such as users older than 18 or products priced over 100.

Column comparison

Compare two fields and retain rows where one column exceeds another.

Range conditions

Combine a lower bound with lt to select values inside an exclusive range.

Interview questions

QWhat does gt do?

gt is Drizzle ORM's greater-than filter operator. It can compare a column with a value, producing a SQL > predicate in a where clause.

Follow-up: How can it compare two columns? Pass both column expressions, such as gt(table.column1, table.column2), which produces a column-to-column > comparison.

QHow do you use gt in a query?

Import gt from drizzle-orm and pass the left-hand expression plus the value or expression to compare against. For example, where(gt(table.column, 5)) selects rows whose column exceeds 5.

Follow-up: How is the runtime value handled? Drizzle parameterizes values supplied to filter operators automatically.

QHow can gt express a range?

gt can be combined with other filter operators through logical operators such as and. A range can therefore be expressed with and(gt(table.column, 5), lt(table.column, 7)).

Follow-up: What SQL shape does that produce? Drizzle emits a parenthesized conjunction containing the greater-than and less-than predicates.

  • gte
  • lt
  • lte
  • eq
  • ne
  • and
  • or
  • sql

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