Skip to content

Add default SQLite REGEXP support - #1770

Open
Chen-dreamyu wants to merge 5 commits into
neuml:masterfrom
Chen-dreamyu:docs/sqlite-regexp-function
Open

Chen-dreamyu wants to merge 5 commits into
neuml:masterfrom
Chen-dreamyu:docs/sqlite-regexp-function

Conversation

@Chen-dreamyu

@Chen-dreamyu Chen-dreamyu commented Dec 4, 2026 •

Copy link
Copy Markdown

Summary

Register a default Python regular-expression function for SQLite so queries using REGEXP work without custom configuration. A user-provided function named regexp continues to take precedence, and NULL inputs do not match. Update the query documentation to describe the default and customization.

Closes #1769. Related: #1625 and #1626 fixed SQL parsing.

Validation

  • On Windows: PYTHONPATH=src/python;test/python python -m unittest testdatabase.testsql — 37 tests passed, including default, NULL and custom override cases.
  • python -m black --check src/python/txtai/database/sqlite.py test/python/testdatabase/testsql.py and git diff --check passed.

The environment emitted NumPy/SciPy binary compatibility warnings during imports. The full suite and other operating systems were not run. Prepared with AI assistance.

@davidmezzetti

Copy link
Copy Markdown
Member

Thank you for this PR.

What if instead of documenting this, we added a default regexp function for SQLite? Seems like there wouldn't be a downside to it.

The idea would be we'd check self.functions for a key regexp. If it didn't exist we'd add a reference to the regex function you proposed. Perhaps as simple as this:

if "regexp" not in self.functions:
  conn.create_function(
      "regexp", 2,
      lambda pattern, value: re.search(pattern, value) is not None
  )

or we could have on SQLite:

def regexp(self, pattern, value):
    return value is not None and re.search(pattern, value) is not None

if "regexp" not in self.functions:
    conn.create_function("regexp", 2, self.regexp)

@Chen-dreamyu

Copy link
Copy Markdown
Author

Thanks for the suggestion! I updated the branch in e73487c to register a default SQLite regexp function, while preserving custom regexp functions (including differently cased names). NULL inputs do not match. The documentation now describes the default and the override.

Validation on Windows: PYTHONPATH=src/python;test/python python -m unittest testdatabase.testsql — 37 passed; python -m black --check src/python/txtai/database/sqlite.py test/python/testdatabase/testsql.py and git diff --check passed. The environment emitted existing NumPy/SciPy compatibility warnings; the complete suite and other platforms were not run.

@Chen-dreamyu Chen-dreamyu changed the title Document SQLite REGEXP function setup Add default SQLite REGEXP support Dec 6, 2026
@davidmezzetti

Copy link
Copy Markdown
Member

Please see build errors. The tests need to be alphabetically ordered and the test name is too long. You can run the same checks locally.

This branch has not been deployed

No deployments
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.

Document how to use REGEXP with the SQLite content database

2 participants