Skip to content

Issue 4130 similaritySearch throwing Exception due to schema name fix #4166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wilocu
Copy link
Contributor

@wilocu wilocu commented Aug 15, 2025

#4130

Problem
When using PgVectorStore with schema names containing hyphens (e.g., demo-1998), similaritySearch() operations would throw SQL grammar exceptions due to
unquoted PostgreSQL identifiers in generated SQL.

Solution

  • Added proper PostgreSQL identifier quoting in getFullyQualifiedTableName() to generate "schema"."table" format
  • Updated schema creation DDL to use quoted schema names
  • Enhanced schema validator to accept hyphenated names while maintaining security against SQL injection
  • Updated error messages to show proper quoted syntax in help text

Changes

  • PgVectorStore.java: Fixed SQL generation to use quoted identifiers
  • PgVectorSchemaValidator.java: Updated validation logic and error messages
  • PgVectorStoreSchemaQuotingTest.java: Added test coverage for hyphenated schema names

Example

Before (❌ SQL error):
SELECT * FROM demo-1998.vector_store -- Syntax error

After (✅ Valid PostgreSQL):
SELECT * FROM "demo-1998"."vector_store" -- Works correctly

Testing

  • All existing tests pass
  • New test verifies proper quoting for hyphenated schema names
  • Verified SQL generation produces valid PostgreSQL syntax

Signed-off-by: Mattia Pasetto [email protected]

I am still pretty new to contributions, please double check and let me know of any errors.

Signed-off-by: Mattia Pasetto <[email protected]>
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