0

I'm trying to create a table in SQLite that contains a text column, several integer columns, and a final column that is the sum of all integers in that row.

This is my attempt:

CREATE TABLE example1(name TEXT,
                      num1 INT,
                      num2 INT,
                      num3 INT,
                      num_total REAL GENERATED ALWAYS AS (num1 + num2 + num3));

And the error message is

Execution finished with errors.
Result: near "AS": syntax error
At line 1:
CREATE TABLE example1(name TEXT,
                      num1 INT,
                      num2 INT,
                      num3 INT,
                      num_total REAL GENERATED ALWAYS AS

Any help is much appreciated, thanks.

Ash
  • 1
  • 1
  • 1
    What version of SQLite are you using? This capability was added in 3.31.0. – Gordon Linoff Oct 16 '20 at 17:29
  • I am using version 3.31.1, so I guess it should be there – Ash Oct 17 '20 at 15:52
  • . . The error that you are getting is the error you would get if it were not supported. And the code works where it is supported. You can run `select sqlite_version()` just to verify the version. – Gordon Linoff Oct 17 '20 at 16:42
  • You were right! Tried it in SQL server rather than SQLite and it worked- I just had to put in an ID column. Thanks! – Ash Oct 19 '20 at 10:00

0 Answers0