Skip to content

Commit c74f4f1

Browse files
georgeh0claude
andauthored
fix(postgres): install pgvector extension into default schema (#1979)
The connector previously installed pgvector via `CREATE EXTENSION IF NOT EXISTS vector WITH SCHEMA "<pg_schema_name>"`, which placed the `vector` type inside the table's schema. The subsequent `CREATE TABLE` / `ALTER TABLE` then referenced the unqualified `vector(N)` type and failed with `type "vector" does not exist` because the table's schema is not on the default `search_path`. Extensions are a database-wide resource, so the right model is to install into the extension's default schema (typically `public`, already on `search_path`) regardless of where the target table lives. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 6f8a71d commit c74f4f1

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

python/cocoindex/connectors/postgres/_target.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -961,16 +961,17 @@ async def _drop_table(
961961
async def _ensure_pgvector_extension(
962962
self,
963963
conn: asyncpg.pool.PoolConnectionProxy[asyncpg.Record],
964-
pg_schema_name: str | None,
965964
) -> None:
966965
"""
967966
Ensure the pgvector extension is installed.
968967
969-
Postgres extensions are installed per-database but can live in a chosen
970-
schema; when `pg_schema_name` is provided we request installing into it.
968+
The extension is installed into its default schema (typically `public`),
969+
which is on the default `search_path`. We deliberately do not tie the
970+
extension's location to the target table's schema: extensions are a
971+
database-wide resource, and pinning `vector` to a per-app schema would
972+
leave the unqualified `vector(N)` references in DDL unresolved.
971973
"""
972-
schema_clause = f' WITH SCHEMA "{pg_schema_name}"' if pg_schema_name else ""
973-
await conn.execute(f"CREATE EXTENSION IF NOT EXISTS vector{schema_clause}")
974+
await conn.execute("CREATE EXTENSION IF NOT EXISTS vector")
974975

975976
async def _create_table(
976977
self,
@@ -989,7 +990,7 @@ async def _create_table(
989990

990991
# Ensure pgvector extension exists if needed by any column type.
991992
if _schema_uses_pgvector(schema):
992-
await self._ensure_pgvector_extension(conn, key.pg_schema_name)
993+
await self._ensure_pgvector_extension(conn)
993994

994995
# Build column definitions
995996
col_defs = []
@@ -1025,7 +1026,7 @@ async def _apply_column_actions(
10251026
for sub_key, action in column_actions.items():
10261027
if sub_key == _EXT_PGVECTOR_SUBKEY:
10271028
if action != "delete":
1028-
await self._ensure_pgvector_extension(conn, key.pg_schema_name)
1029+
await self._ensure_pgvector_extension(conn)
10291030
continue
10301031

10311032
if not sub_key.startswith(_COL_SUBKEY_PREFIX):

0 commit comments

Comments
 (0)