ยฉ 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Teamโ€ข2y agoโ€ข
2 replies
Paul

How to set a GIN index on the JSONB column?

How can I set a GIN index on the whole jsonb column and also on a single column?

import { sql } from "drizzle-orm";
import { index, jsonb, pgTable } from "drizzle-orm/pg-core";

export const users = pgTable("users", {
  metadata: jsonb("metadata").$type<Record<string, any>>(),
}, t => ({
  ginIndex: index("gin_idx").on(t.metadata).using(sql`gin`),
  ginIndex2: index("gin_idx_2").on(t.metadata).using(sql`GIN ((metadata->'name'))`),
}));
import { sql } from "drizzle-orm";
import { index, jsonb, pgTable } from "drizzle-orm/pg-core";

export const users = pgTable("users", {
  metadata: jsonb("metadata").$type<Record<string, any>>(),
}, t => ({
  ginIndex: index("gin_idx").on(t.metadata).using(sql`gin`),
  ginIndex2: index("gin_idx_2").on(t.metadata).using(sql`GIN ((metadata->'name'))`),
}));


Is currently giving me this only:
CREATE TABLE IF NOT EXISTS "users" (
    "metadata" jsonb
);
--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "users_metadata_gin_idx" ON "users" ("metadata");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "users_metadata_name_gin_idx" ON "users" ("metadata");
CREATE TABLE IF NOT EXISTS "users" (
    "metadata" jsonb
);
--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "users_metadata_gin_idx" ON "users" ("metadata");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "users_metadata_name_gin_idx" ON "users" ("metadata");
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

How to create GIN/GIST index on text[] column?
Drizzle TeamDTDrizzle Team / help
3y ago
GIN index
Drizzle TeamDTDrizzle Team / help
3y ago
Create GIN index in Postgres
Drizzle TeamDTDrizzle Team / help
3y ago
How to create jsonb attribute index in drizzle
Drizzle TeamDTDrizzle Team / help
3y ago