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

Can't use in expressions for generated stored columns #3

Open
natskvi opened this issue Mar 4, 2022 · 0 comments
Open

Can't use in expressions for generated stored columns #3

natskvi opened this issue Mar 4, 2022 · 0 comments

Comments

@natskvi
Copy link
Contributor

natskvi commented Mar 4, 2022

Thanks for making this library available, I found it useful.

Minor problem: Because you specify the SQLITE_ANY type in all five sqlite3_create_function() statements in digest.c, the digest functions cannot be used in expressions for generated stored columns. For example, the following table definition will fail:

$ sqlite3
SQLite version 3.37.2 2022-01-06 13:25:41
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> CREATE TABLE messages (
  id         INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 
  size       INTEGER NOT NULL GENERATED ALWAYS AS (iif(data IS NULL, 0, length(data))) STORED,
  sha256     VARCHAR NOT NULL GENERATED ALWAYS AS (iif(data IS NULL, NULL, hex(digest(data, 'sha256')))) STORED, 
  data       BLOB
);
Error: in prepare, non-deterministic functions prohibited in generated columns (1)

This is in agreement with the SQLite documentation for generated columns:

The expression of a generated column may only reference constant literals and columns within the same row, and may only use scalar deterministic functions. The expression may not use subqueries, aggregate functions, window functions, or table-valued functions.

This issue should be resolved by changing SQLITE_ANY to SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC for all five sqlite3_create_function() statements in digest.c.

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

No branches or pull requests

1 participant