SQLite Forum

The word 'STORED' not show up in the lang_keywords.html page.

The word 'STORED' not show up in the lang_keywords.html page.

(1) By anonymous on 2020-06-14 11:05:10 [link] [source]

The Generated Columns feature has an option that can set the column store type to 'STORED' or 'VIRTUAL'.

Noticed that the word 'STORED' not listed in the https://www.sqlite.org/lang_keywords.html page, so maybe this is a bug?

(2) By Richard Hipp (drh) on 2020-06-14 18:08:31 in reply to 1 [source]

It's an ambiguous situation.

If you look at the low-level implementation, STORED is not parsed as a keyword. In other words, the "sqlite3KeywordCode()" routine will say that "STORED" is not a keyword. The SQL language grammar rules used for generated columns in SQLite looks like this:

   ccons ::= GENERATED ALWAYS AS generated.
   ccons ::= AS generated.
   generated ::= LP expr(E) RP.          {sqlite3AddGenerated(pParse,E,0);}
   generated ::= LP expr(E) RP ID(TYPE). {sqlite3AddGenerated(pParse,E,&TYPE);}

The optional "VIRTUAL" or "STORED" that occurs after the generated column definition is parsed as a normal identifier and is passed into the "sqlite3AddGenerated()" routine. Then inside of sqlite3AddGenerated() (on lines 1674 to 1682) there is logic to error-out if the identifier is anything other than "VIRTUAL" or "STORED".

So, from the point of view of SQLite itself, "STORED" is not a keyword.

On the other hand, from the user's perspective, "STORED" does act like a keyword, even if it is not. So maybe the documentation should be changed to call it a keyword even though it is not.

I'm not sure...

(3) By Larry Brasfield (LarryBrasfield) on 2020-06-14 18:44:34 in reply to 2 [link] [source]

It is a keyword in some contexts and not in (most) others. Is this not similar to SQLite's (parser's) willingness to permit some keywords as identifiers? Are those keywords specially mentioned in the docs?

(No opinion or recommendation here, just consideration.)

I do opine that the issue is not whether the tokenizer treats it as a keyword so much as whether it is good practice to avoid using the word as an identifier. That is why (I suppose) people look at keyword lists. "Good practice" encompasses avoiding the creation of confusing SQL, so that consideration may justify calling STORED and VIRTUAL keywords.

(4) By anonymous on 2020-06-15 05:42:33 in reply to 3 [link] [source]

That is probably correct, so yes it would probably justify calling STORED and VIRTUAL keywords (although VIRTUAL is already a keyword anyways (in CREATE VIRTUAL TABLE), although not a reserved word).

I think that it would also be useful for the documentation to distinguish between keywords that are reserved words and keywords that are not reserved words (possibly by adding asterisks next to the ones that are reserved, or next to the ones that are not reserved).