Skip to content

Commit 766a498

Browse files
committed
Support parsing doubly quoted strings as identifiers
Per https://www.sqlite.org/lang_keywords.html, SQLite supports identifiers expressed as strings surrounded between double quotes: $ sqlite3 SQLite version 3.52.0 2026-03-06 16:01:44 Enter ".help" for usage hints. Connected to a transient in-memory database. Use ".open FILENAME" to reopen on a persistent database. sqlite> create table a("oh,boy!" TEXT); sqlite> pragma table_info(a); ╭─────┬─────────┬──────┬─────────┬────────────┬────╮ │ cid │ name │ type │ notnull │ dflt_value │ pk │ ╞═════╪═════════╪══════╪═════════╪════════════╪════╡ │ 0 │ oh,boy! │ TEXT │ 0 │ NULL │ 0 │ ╰─────┴─────────┴──────┴─────────┴────────────┴────╯ When identifiers are parsed as such, no escaping applies, i.e. backslashes don't affect the next character: sqlite> create table b("oh\tno\" TEXT); sqlite> pragma table_info(b); ╭─────┬─────────┬──────┬─────────┬────────────┬────╮ │ cid │ name │ type │ notnull │ dflt_value │ pk │ ╞═════╪═════════╪══════╪═════════╪════════════╪════╡ │ 0 │ oh\tno\ │ TEXT │ 0 │ NULL │ 0 │ ╰─────┴─────────┴──────┴─────────┴────────────┴────╯ Make sqlite-vec internal scanner handle these identifiers, so that the column names in a vec0 virtual table may have the same (reduced) limitations as any other SQLite table. Note: SQLite also implements similar support for single quoted strings to be handled as identifiers. This is done for compatibility with other SQL implementations rather than standard conformance, so it's perhaps a bit more dubious to support.
1 parent 5778fec commit 766a498

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

sqlite-vec.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,6 +2157,17 @@ int vec0_token_next(char *start, char *end, struct Vec0Token *out) {
21572157
out->end = ptr;
21582158
out->token_type = TOKEN_TYPE_IDENTIFIER;
21592159
return VEC0_TOKEN_RESULT_SOME;
2160+
} else if (curr == '"') {
2161+
char *start = ptr;
2162+
int match = 0;
2163+
do {
2164+
match = ptr > start && (*ptr == '"');
2165+
ptr++;
2166+
} while (ptr < end && !match);
2167+
out->start = start;
2168+
out->end = ptr;
2169+
out->token_type = TOKEN_TYPE_IDENTIFIER;
2170+
return VEC0_TOKEN_RESULT_SOME;
21602171
} else if (is_digit(curr)) {
21612172
char *start = ptr;
21622173
while (ptr < end && (is_digit(*ptr))) {

0 commit comments

Comments
 (0)