Skip to content

[Pg-kit] fix: use opcname instead of amname for index operator class introspection#5496

Open
sleitor wants to merge 1 commit intodrizzle-team:betafrom
sleitor:fix-5495
Open

[Pg-kit] fix: use opcname instead of amname for index operator class introspection#5496
sleitor wants to merge 1 commit intodrizzle-team:betafrom
sleitor:fix-5495

Conversation

@sleitor
Copy link
Copy Markdown

@sleitor sleitor commented Mar 16, 2026

Problem

Fixes #5495

When running drizzle-kit pull against PostgreSQL databases with pgvector ivfflat indexes (or other non-default access methods), the generated schema uses the access method name (ivfflat) in the operator class position instead of the actual operator class (e.g. vector_cosine_ops).

Incorrect output:

index("idx").using("ivfflat", table.embedding.asc().nullsLast().op("ivfflat"))

which generates invalid SQL:

CREATE INDEX ... USING ivfflat (embedding ivfflat);

Root Cause

In drizzle-kit/src/dialects/postgres/introspect.ts (and aws-introspect.ts), the opclasses subquery built an array of {oid, name, default} objects for each index column, but used pg_am.amname (the access method name) instead of pg_opclass.opcname (the operator class name).

Fix

Replace pg_am.amname with pg_opclass.opcname in the opclasses subquery, and remove the now-unnecessary JOIN pg_catalog.pg_am from that subquery (the outer query already joins pg_am for the index access method).

Correct output:

index("idx").using("ivfflat", table.embedding.asc().nullsLast().op("vector_cosine_ops"))

which generates valid SQL:

CREATE INDEX ... USING ivfflat (embedding vector_cosine_ops);

Changes

  • drizzle-kit/src/dialects/postgres/introspect.ts: use pg_opclass.opcname instead of pg_am.amname, remove unused pg_am JOIN from opclasses subquery
  • drizzle-kit/src/dialects/postgres/aws-introspect.ts: same fix
  • drizzle-kit/tests/postgres/pull.test.ts: add test for ivfflat index opclass introspection using PGlite's vector extension

…erator class introspection

Fixes drizzle-team#5495

When introspecting PostgreSQL indexes (e.g. ivfflat from pgvector),
the operator class subquery was joining pg_am and using amname (the
access method name, e.g. 'ivfflat') instead of pg_opclass.opcname
(the actual operator class name, e.g. 'vector_cosine_ops').

This caused drizzle-kit pull to generate incorrect SQL like:
  CREATE INDEX ... USING ivfflat (embedding ivfflat)
instead of:
  CREATE INDEX ... USING ivfflat (embedding vector_cosine_ops)

Fix: replace pg_am.amname with pg_opclass.opcname in the opclasses
array subquery and remove the now-unnecessary pg_am JOIN.

Applies to both postgres/introspect.ts and postgres/aws-introspect.ts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant