{"record":{"id":"c60f64ff5818a552","repo":"spring-projects/spring-ai","slug":"error-while-validating-table-schema-table-does-n","errorCode":null,"errorMessage":"Error while validating table schema, Table  does not exist in schema ","messagePattern":"Error while validating table schema, Table  does not exist in schema ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/pgvector/PgVectorSchemaValidator.java","lineNumber":120,"sourceCode":"\t\t\tif (logger.isInfoEnabled()) {\n\t\t\t\tlogger.info(\"Validating PGVectorStore schema for table: \" + tableName + \" in schema: \" + schemaName);\n\t\t\t}\n\n\t\t\tList<String> expectedColumns = new ArrayList<>();\n\t\t\texpectedColumns.add(\"id\");\n\t\t\texpectedColumns.add(\"content\");\n\t\t\texpectedColumns.add(\"metadata\");\n\t\t\texpectedColumns.add(\"embedding\");\n\n\t\t\t// Query to check if the table exists with the required fields and types\n\t\t\t// Include the schema name in the query to target the correct table\n\t\t\tString query = \"SELECT column_name, data_type FROM information_schema.columns \"\n\t\t\t\t\t+ \"WHERE table_schema = ? AND table_name = ?\";\n\t\t\tList<Map<String, @Nullable Object>> columns = this.jdbcTemplate.queryForList(query,\n\t\t\t\t\tnew Object[] { schemaName, tableName });\n\n\t\t\tif (columns.isEmpty()) {\n\t\t\t\tthrow new IllegalStateException(\"Error while validating table schema, Table \" + tableName\n\t\t\t\t\t\t+ \" does not exist in schema \" + schemaName);\n\t\t\t}\n\n\t\t\t// Check each column against expected fields\n\t\t\tList<String> availableColumns = new ArrayList<>();\n\t\t\tfor (Map<String, @Nullable Object> column : columns) {\n\t\t\t\tString columnName = (String) column.get(\"column_name\");\n\t\t\t\tavailableColumns.add(columnName);\n\n\t\t\t}\n\n\t\t\texpectedColumns.removeAll(availableColumns);\n\n\t\t\tif (expectedColumns.isEmpty()) {\n\t\t\t\tlogger.info(\"PG VectorStore schema validation successful\");\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new IllegalStateException(\"Missing fields \" + expectedColumns);","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/pgvector/PgVectorSchemaValidator.java#L102-L138","documentation":"After confirming table existence, validateTableSchema queries information_schema.columns for the table's columns; an empty result triggers this IllegalStateException. This indicates the table vanished, the schema/table parameters don't match (e.g. case sensitivity or wrong schema), or permissions hide the columns.","triggerScenarios":"information_schema.columns returns no rows for (schemaName, tableName) despite isTableExists succeeding — schema name case mismatch, table dropped concurrently, or querying the wrong schema.","commonSituations":"Mixed-case or quoted identifiers in PostgreSQL that information_schema stores lowercase; concurrent migrations dropping/recreating the table between the two checks; role without USAGE on the schema.","solutions":["Check information_schema.columns for the exact table_schema/table_name values and align your configuration.","Use lowercase, unquoted identifiers for schema and table in configuration.","Re-run initialization (initializeSchema=true) to recreate a dropped table.","Grant the connecting role USAGE/SELECT on the schema."],"exampleFix":"// before\n.schema(\"MySchema\") // PostgreSQL folds to my_schema; mismatch can yield empty columns\n// after\n.schema(\"my_schema\")","handlingStrategy":"validation","validationCode":"int cols = jdbcTemplate.queryForObject(\n    \"SELECT count(*) FROM information_schema.columns WHERE table_schema=? AND table_name=?\",\n    Integer.class, schemaName, tableName);\nif (cols == 0) {\n    throw new IllegalStateException(\"No columns visible for \" + schemaName + \".\" + tableName + \" — check identifiers/permissions\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    validate(schemaName, tableName, dims);\n} catch (IllegalStateException e) {\n    if (e.getMessage().startsWith(\"Error while validating table schema\")) {\n        // verify identifier case and schema USAGE grants\n    } else { throw e; }\n}","preventionTips":["Use lowercase unquoted PostgreSQL identifiers everywhere.","Avoid dropping/recreating the table while the app starts.","Grant the app role USAGE and SELECT on the schema."],"tags":["pgvector","schema-validation","database"],"backgroundTag":"schema-validation-failed","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}