-
Couldn't load subscription status.
- Fork 579
Description
If a DEFAULT clause contains column names that are quoted with backticks, double quotes or brackets, they are incorrectly resolved as literal strings. For example:
turso> create table t(a, b default (coalesce(`a`, `b`)));
turso> insert into t default values;
turso> insert into t(a) values (123);
turso> select * from t;
┌─────┬───┐
│ a │ b │
├─────┼───┤
│ │ a │
├─────┼───┤
│ 123 │ a │
└─────┴───┘
This contradicts the documentation for quoted identifiers:
A keyword enclosed in grave accents (ASCII code 96) is an identifier.
If a keyword in double quotes (ex: "key" or "glob") is used in a context where it cannot be resolved to an identifier but where a string literal is allowed, then the token is understood to be a string literal instead of an identifier.
A keyword enclosed in square brackets is an identifier.
But the best solution might just be to forbid these types of expressions, like SQLite does. In the documentation, it says that the expression in parentheses has to be constant, and they define constant as:
if it contains no sub-queries, column or table references, bound parameters, or string literals enclosed in double-quotes instead of single-quotes. (source)
That's why the first SQL statement above is rejected by SQLite:
sqlite> create table t(a, b default (coalesce(`a`, `b`)));
Parse error: default value of column [b] is not constant