{"record":{"id":"99123cc74b6e0e66","repo":"cocoindex-io/cocoindex","slug":"column-column-not-found-in-table-schema-list-99123c","errorCode":null,"errorMessage":"Column '{column}' not found in table schema: {list(self._table_schema.columns.keys())}","messagePattern":"Column '(.+?)' not found in table schema: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/postgres/_target.py","lineNumber":1347,"sourceCode":"        \"\"\"\n        Declare a pgvector index on a column of this table.\n\n        The actual Postgres index will be named ``{table_name}__vector__{name}``.\n\n        Args:\n            name: Logical index name (defaults to ``column``).\n            column: Column to index.\n            metric: Distance metric (\"cosine\", \"l2\", or \"ip\").\n            method: Index method (\"ivfflat\" or \"hnsw\").\n            lists: Number of lists (ivfflat only).\n            m: Maximum number of connections per layer (hnsw only).\n            ef_construction: Size of the dynamic candidate list (hnsw only).\n        \"\"\"\n        if name is None:\n            name = column\n        col_def = self._table_schema.columns.get(column)\n        if col_def is None:\n            raise ValueError(\n                f\"Column '{column}' not found in table schema: {list(self._table_schema.columns.keys())}\"\n            )\n        spec = _VectorIndexSpec(\n            column=column,\n            metric=metric,\n            op_class=_pgvector_op_class(column, col_def.type, metric),\n            method=method,\n            lists=lists,\n            m=m,\n            ef_construction=ef_construction,\n        )\n        att_provider = self._provider.attachment(\"vector_index\")\n        coco.declare_target_state(att_provider.target_state(name, spec))\n\n    def declare_sql_command_attachment(\n        self: \"TableTarget[RowT]\",\n        *,\n        name: str,","sourceCodeStart":1329,"sourceCodeEnd":1365,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/postgres/_target.py#L1329-L1365","documentation":"Raised by `declare_vector_index` when the requested column does not exist in the table's declared schema. The lookup `self._table_schema.columns.get(column)` returns None, and the error lists the valid column names to help identify the mistake.","triggerScenarios":"Calling `table.declare_vector_index(column='embeddings', ...)` where 'embeddings' is not among the declared column names — typo, wrong singular/plural, or the vector column was never declared in the row dataclass/table schema.","commonSituations":"Renaming a field in the row dataclass but not in the index declaration; referencing the raw embedding column before it was declared; case mismatch on the column name.","solutions":["Read the valid column names from the error message and use one of them exactly.","Add the embedding field to the table/row schema so the column is declared before declaring the index.","Fix typos and match the case of the declared column name.","Ensure declare_vector_index is called after the table schema (row type) is finalized, not on a modified copy."],"exampleFix":"// before\ntable.declare_vector_index(column=\"embedding_vec\", metric=\"cosine\")\n// after\ntable.declare_vector_index(column=\"embedding\", metric=\"cosine\")","handlingStrategy":"validation","validationCode":"# before calling:\n# if column not in table_schema.columns:\n#     raise KeyError(f\"{column} not in {list(table_schema.columns)}\")","typeGuard":"def column_exists(schema, column: str) -> bool:\n    return column in schema.columns","tryCatchPattern":"try:\n    table.declare_vector_index(column=col, metric=\"cosine\")\nexcept ValueError as e:\n    if \"not found in table schema\" in str(e):\n        logger.error(\"Available columns: %s\", str(e).rsplit(':', 1)[-1])\n    else:\n        raise","preventionTips":["Derive index column names from the same constants/dataclass used for the row schema.","Rename-check with grep before renaming dataclass fields.","Keep declare_vector_index calls adjacent to the schema declaration for review."],"tags":["postgres","column-not-found","schema"],"backgroundTag":"record-not-found","analyzedSha":"e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b","analyzedAt":"2026-09-08T15:59:19.997Z","contentChangedAt":"2026-09-08T15:59:19.997Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}