{"record":{"id":"c63242d3f6dcdebf","repo":"spring-projects/spring-ai","slug":"table-name-should-only-contain-alphanumeric-charac","errorCode":null,"errorMessage":"Table name should only contain alphanumeric characters and underscores","messagePattern":"Table name should only contain alphanumeric characters and underscores","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/pgvector/PgVectorSchemaValidator.java","lineNumber":88,"sourceCode":"\tboolean isTableExists(String schemaName, String tableName) {\n\t\tString sql = \"SELECT 1 FROM information_schema.tables WHERE table_schema = ? AND table_name = ?\";\n\t\ttry {\n\t\t\t// Query for a single integer value, if it exists, table exists\n\t\t\tthis.jdbcTemplate.queryForObject(sql, Integer.class, schemaName, tableName);\n\t\t\treturn true;\n\t\t}\n\t\tcatch (DataAccessException e) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tvoid validateNames(String schemaName, String tableName) {\n\t\tif (!isValidNameForDatabaseObject(schemaName)) {\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\"Schema name should only contain alphanumeric characters and underscores\");\n\t\t}\n\t\tif (!isValidNameForDatabaseObject(tableName)) {\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\"Table name should only contain alphanumeric characters and underscores\");\n\t\t}\n\t}\n\n\tvoid validateTableSchema(String schemaName, String tableName, int dimensions) {\n\n\t\tvalidateNames(schemaName, tableName);\n\n\t\tif (!isTableExists(schemaName, tableName)) {\n\t\t\tthrow new IllegalStateException(\"Table \" + tableName + \" does not exist in schema \" + schemaName);\n\t\t}\n\n\t\ttry {\n\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<>();","sourceCodeStart":70,"sourceCodeEnd":106,"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#L70-L106","documentation":"validateNames also rejects table names that are not purely alphanumeric with underscores, for the same injection/quoting safety reasons as the schema name check. It runs before any SQL is issued against the table.","triggerScenarios":"Building PgVectorStore with a table name containing hyphens, dots, spaces, or quotes (e.g. \"vector-store\") while schema validation is enabled (validateTableSchema -> validateNames).","commonSituations":"Table name taken from a kebab-case config key or Docker/service name; table auto-named from an app name with dashes; tenant-per-table naming schemes with separators.","solutions":["Rename the table to only alphanumerics/underscores (e.g. vector_store).","Sanitize the configured table name before passing it to the builder.","Check the vectorStoreTableName config property for stray quotes or whitespace."],"exampleFix":"// before\nPgVectorStore.builder(jdbcTemplate, embeddingModel)\n    .vectorTableName(\"vector-store\").build();\n// after\nPgVectorStore.builder(jdbcTemplate, embeddingModel)\n    .vectorTableName(\"vector_store\").build();","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(tableName, \"table\");\nif (!tableName.matches(\"[A-Za-z0-9_]+\")) {\n    throw new IllegalArgumentException(\"Table name must be alphanumeric/underscore: \" + tableName);\n}","typeGuard":null,"tryCatchPattern":"try {\n    PgVectorStore store = builder.build();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"Table name\")) {\n        throw new ConfigurationException(\"Fix vectorStoreTableName property\", e);\n    }\n    throw e;\n}","preventionTips":["Use snake_case table names (e.g. vector_store).","Strip hyphens/whitespace from names generated from service or app names.","Add a startup config validation bean that checks both schema and table names."],"tags":["pgvector","schema-validation","naming"],"backgroundTag":"invalid-identifier-format","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"}