Skip to content
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

fix(sqlite): allow using fts5 table name in the where clause #3498

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

Conversation

naspeh
Copy link

@naspeh naspeh commented Jul 22, 2024

Fixes: #3204

Allow using table name to the left of MATCH or equality operator.

Related:

@naspeh
Copy link
Author

naspeh commented Aug 6, 2024

@kyleconroy Thank you for sqlc !

Could you look at this PR, please?

I have to use my fork as a workaround. Would love to get this in the official package.

@@ -168,6 +168,12 @@ func (c *cc) convertCreate_virtual_table_fts5(n *parser.Create_virtual_table_stm
}
}

stmt.Cols = append(stmt.Cols, &ast.ColumnDef{
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be fine to include the fts5 table name in the column list, as SQLite supports this as well

sqlite> SELECT key, emails_fts FROM emails_fts limit 1;
┌───────────────────────────────────────────────────┬────────────┐
│                        key                        │ emails_fts │
├───────────────────────────────────────────────────┼────────────┤
│ 1708522984.M224116P268.c18ac5293f65,S=3578,W=3701 │ 5          │
└───────────────────────────────────────────────────┴────────────┘

@kyleconroy
Copy link
Collaborator

Could you please rebase this on the latest main? The tests didn't run when it was originally opened.

@naspeh naspeh force-pushed the sqlite-ft5-where-by-table-name branch from d2e447d to a4bbafc Compare November 26, 2024 20:28
@naspeh
Copy link
Author

naspeh commented Nov 26, 2024

@kyleconroy Done 🟢!

@ororsatti
Copy link

is this going to be merged anytime soon?

@awgaan
Copy link

awgaan commented Dec 26, 2024

@naspeh I am joining the FTS5 table in a query and use it in WHERE. This does not seem to work on your branch. Expected behavior?

@naspeh
Copy link
Author

naspeh commented Dec 26, 2024

@awgaan it should work, I think. I can't check, I lost context for this branch as I stopped using sqlc on the project.

@awgaan
Copy link

awgaan commented Dec 26, 2024

Turns out sqlc treats fts5 as a case sensitive token. Creating a virtual table with USING FTS5 does not generate the correct models. That was hard af to debug.

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.

SQLite: Add support for WHERE clause on the FTS5 Table Name
4 participants