[D1] Incorrect example code in D1 generated columns documentation #14579
Labels
content:edit
Request for content edits
documentation
Documentation edits
product:d1
D1: https://developers.cloudflare.com/d1/
Existing documentation URL(s)
https://developers.cloudflare.com/d1/reference/generated-columns/
What changes are you suggesting?
In the Examples section, for the resultant table to be valid, allow INSERTing new records, and work as expected, the example code should be changed from:
ADD COLUMN expires_at AS (date('now', '+30 days');
to
ADD COLUMN expires_at AS (date(timestamp, '+30 days');
Additional information
The Additional Considerations section immediately underneath even mentions that generated columns can only use deterministic functions, and
date('now')
isn't deterministic, so whilst the code will execute and update the table, you'll get an error when trying to INSERT into that table.Even if it did let you INSERT records, it'd not work as intended, because the VIRTUAL column expression would be evaluated every time it was read, and so would always be 30 days in the future; the query to return expired records would therefore never return any records.
The text was updated successfully, but these errors were encountered: