How to create jsonb stored and default column at the same time?

I’ve tried:

invalid syntax: statement ignored: syntax error at or near "as"
CREATE TABLE t(
id INT PRIMARY KEY DEFAULT unique_rowid() AS (data->>'id') STORED,
                                          ^

or

invalid syntax: statement ignored: syntax error at or near "as"
CREATE TABLE t(
id INT PRIMARY KEY AS (data->>'id') STORED DEFAULT unique_rowid(),
                   ^

both gives an error, or it’s not possible to do so?

What you are trying does not make sense. If the value is computed from another column, it always has a value and therefore a DEFAULT clause is non-sensical.

Are you suggesting that the expression data->>'id' may not have a value and return NULL sometimes? in that case you can use this:

id INT PRIMARY KEY AS (IFNULL(data->>'id', unique_rowid())) STORED

Does this help?