src/content/docs/operators.mdx
import IsSupportedChipGroup from '@mdx/IsSupportedChipGroup.astro'; import Section from '@mdx/Section.astro';
We natively support all dialect specific filter and conditional operators.
You can import all filter & conditional from drizzle-orm:
import { eq, ne, gt, gte, ... } from "drizzle-orm";
<IsSupportedChipGroup chips={{ 'PostgreSQL': true, 'MySQL': true, 'SQLite': true, 'SingleStore': true }} />
Value equal to n
db.select().from(table).where(eq(table.column, 5));
```sql copy
SELECT * FROM table WHERE table.column = 5
db.select().from(table).where(eq(table.column1, table.column2));
```sql
SELECT * FROM table WHERE table.column1 = table.column2
<IsSupportedChipGroup chips={{ 'PostgreSQL': true, 'MySQL': true, 'SQLite': true, 'SingleStore': true }} />
Value is not equal to n
db.select().from(table).where(ne(table.column, 5));
```sql
SELECT * FROM table WHERE table.column <> 5
db.select().from(table).where(ne(table.column1, table.column2));
```sql
SELECT * FROM table WHERE table.column1 <> table.column2
<IsSupportedChipGroup chips={{ 'PostgreSQL': true, 'MySQL': true, 'SQLite': true, 'SingleStore': true }} />
Value is greater than n
db.select().from(table).where(gt(table.column, 5));
```sql
SELECT * FROM table WHERE table.column > 5
db.select().from(table).where(gt(table.column1, table.column2));
```sql
SELECT * FROM table WHERE table.column1 > table.column2
<IsSupportedChipGroup chips={{ 'PostgreSQL': true, 'MySQL': true, 'SQLite': true, 'SingleStore': true }} />
Value is greater than or equal to n
db.select().from(table).where(gte(table.column, 5));
```sql
SELECT * FROM table WHERE table.column >= 5
db.select().from(table).where(gte(table.column1, table.column2));
```sql
SELECT * FROM table WHERE table.column1 >= table.column2
<IsSupportedChipGroup chips={{ 'PostgreSQL': true, 'MySQL': true, 'SQLite': true, 'SingleStore': true }} />
Value is less than n
db.select().from(table).where(lt(table.column, 5));
```sql
SELECT * FROM table WHERE table.column < 5
db.select().from(table).where(lt(table.column1, table.column2));
```sql
SELECT * FROM table WHERE table.column1 < table.column2
<IsSupportedChipGroup chips={{ 'PostgreSQL': true, 'MySQL': true, 'SQLite': true, 'SingleStore': true }} />
Value is less than or equal to n.
db.select().from(table).where(lte(table.column, 5));
```sql
SELECT * FROM table WHERE table.column <= 5
db.select().from(table).where(lte(table.column1, table.column2));
```sql
SELECT * FROM table WHERE table.column1 <= table.column2
<IsSupportedChipGroup chips={{ 'PostgreSQL': true, 'MySQL': true, 'SQLite': true, 'SingleStore': true }} />
Value exists
<Section> ```typescript import { exists } from "drizzle-orm";const query = db.select().from(table2) db.select().from(table).where(exists(query));
```sql
SELECT * FROM table WHERE EXISTS (SELECT * from table2)
const query = db.select().from(table2) db.select().from(table).where(notExists(query));
```sql
SELECT * FROM table WHERE NOT EXISTS (SELECT * from table2)
<IsSupportedChipGroup chips={{ 'PostgreSQL': true, 'MySQL': true, 'SQLite': true, 'SingleStore': true }} />
Value is null
db.select().from(table).where(isNull(table.column));
```sql
SELECT * FROM table WHERE table.column IS NULL
<IsSupportedChipGroup chips={{ 'PostgreSQL': true, 'MySQL': true, 'SQLite': true, 'SingleStore': true }} />
Value is not null
db.select().from(table).where(isNotNull(table.column));
```sql
SELECT * FROM table WHERE table.column IS NOT NULL
<IsSupportedChipGroup chips={{ 'PostgreSQL': true, 'MySQL': true, 'SQLite': true, 'SingleStore': true }} />
Value is in array of values
<Section> ```typescript import { inArray } from "drizzle-orm";db.select().from(table).where(inArray(table.column, [1, 2, 3, 4]));
```sql
SELECT * FROM table WHERE table.column in (1, 2, 3, 4)
const query = db.select({ data: table2.column }).from(table2); db.select().from(table).where(inArray(table.column, query));
```sql
SELECT * FROM table WHERE table.column IN (SELECT table2.column FROM table2)
<IsSupportedChipGroup chips={{ 'PostgreSQL': true, 'MySQL': true, 'SQLite': true, 'SingleStore': true }} />
Value is not in array of values
<Section> ```typescript import { notInArray } from "drizzle-orm";db.select().from(table).where(notInArray(table.column, [1, 2, 3, 4]));
```sql
SELECT * FROM table WHERE table.column NOT in (1, 2, 3, 4)
const query = db.select({ data: table2.column }).from(table2); db.select().from(table).where(notInArray(table.column, query));
```sql
SELECT * FROM table WHERE table.column NOT IN (SELECT table2.column FROM table2)
<IsSupportedChipGroup chips={{ 'PostgreSQL': true, 'MySQL': true, 'SQLite': true, 'SingleStore': true }} />
Value is between two values
<Section> ```typescript import { between } from "drizzle-orm";db.select().from(table).where(between(table.column, 2, 7));
```sql
SELECT * FROM table WHERE table.column BETWEEN 2 AND 7
<IsSupportedChipGroup chips={{ 'PostgreSQL': true, 'MySQL': true, 'SQLite': true, 'SingleStore': true }} />
Value is not between two value
<Section> ```typescript import { notBetween } from "drizzle-orm";db.select().from(table).where(notBetween(table.column, 2, 7));
```sql
SELECT * FROM table WHERE table.column NOT BETWEEN 2 AND 7
<IsSupportedChipGroup chips={{ 'PostgreSQL': true, 'MySQL': true, 'SQLite': true, 'SingleStore': true }} />
Value is like other value, case sensitive
<Section> ```typescript import { like } from "drizzle-orm";db.select().from(table).where(like(table.column, "%llo wor%"));
```sql
SELECT * FROM table WHERE table.column LIKE '%llo wor%'
<IsSupportedChipGroup chips={{ 'PostgreSQL': true, 'MySQL': false, 'SQLite': false, 'SingleStore': false }} />
Value is like some other value, case insensitive
<Section> ```typescript import { ilike } from "drizzle-orm";db.select().from(table).where(ilike(table.column, "%llo wor%"));
```sql
SELECT * FROM table WHERE table.column ILIKE '%llo wor%'
<IsSupportedChipGroup chips={{ 'PostgreSQL': true, 'MySQL': true, 'SQLite': true, 'SingleStore': true }} />
Value is not like some other value, case insensitive
<Section> ```typescript import { notIlike } from "drizzle-orm";db.select().from(table).where(notIlike(table.column, "%llo wor%"));
```sql
SELECT * FROM table WHERE table.column NOT ILIKE '%llo wor%'
<IsSupportedChipGroup chips={{ 'PostgreSQL': true, 'MySQL': true, 'SQLite': true, 'SingleStore': true }} />
All conditions must return false.
db.select().from(table).where(not(eq(table.column, 5)));
```sql
SELECT * FROM table WHERE NOT (table.column = 5)
<IsSupportedChipGroup chips={{ 'PostgreSQL': true, 'MySQL': true, 'SQLite': true, 'SingleStore': true }} />
All conditions must return true.
db.select().from(table).where(and(gt(table.column, 5), lt(table.column, 7)));
```sql
SELECT * FROM table WHERE (table.column > 5 AND table.column < 7)
<IsSupportedChipGroup chips={{ 'PostgreSQL': true, 'MySQL': true, 'SQLite': true, 'SingleStore': true }} />
One or more conditions must return true.
db.select().from(table).where(or(gt(table.column, 5), lt(table.column, 7)));
```sql
SELECT * FROM table WHERE (table.column > 5 OR table.column < 7)
<IsSupportedChipGroup chips={{ 'PostgreSQL': true, 'MySQL': false, 'SQLite': false, 'SingleStore': false }} />
Test that a column or expression contains all elements of the list passed as the second argument
<Section> ```typescript import { arrayContains } from "drizzle-orm";const contains = await db.select({ id: posts.id }).from(posts) .where(arrayContains(posts.tags, ['Typescript', 'ORM']));
const withSubQuery = await db.select({ id: posts.id }).from(posts) .where(arrayContains( posts.tags, db.select({ tags: posts.tags }).from(posts).where(eq(posts.id, 1)), ));
```sql
select "id" from "posts" where "posts"."tags" @> {Typescript,ORM};
select "id" from "posts" where "posts"."tags" @> (select "tags" from "posts" where "posts"."id" = 1);
<IsSupportedChipGroup chips={{ 'PostgreSQL': true, 'MySQL': false, 'SQLite': false, 'SingleStore': false }} />
Test that the list passed as the second argument contains all elements of a column or expression
<Section> ```typescript import { arrayContained } from "drizzle-orm";const contained = await db.select({ id: posts.id }).from(posts) .where(arrayContained(posts.tags, ['Typescript', 'ORM']));
```sql
select "id" from "posts" where "posts"."tags" <@ {Typescript,ORM};
<IsSupportedChipGroup chips={{ 'PostgreSQL': true, 'MySQL': false, 'SQLite': false, 'SingleStore': false }} />
Test that a column or expression contains any elements of the list passed as the second argument.
<Section> ```typescript import { arrayOverlaps } from "drizzle-orm";const overlaps = await db.select({ id: posts.id }).from(posts) .where(arrayOverlaps(posts.tags, ['Typescript', 'ORM']));
```sql
select "id" from "posts" where "posts"."tags" && {Typescript,ORM}