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

[D1] Incorrect example code in D1 generated columns documentation #14579

Open
ciw1973 opened this issue May 15, 2024 · 0 comments · May be fixed by #14812
Open

[D1] Incorrect example code in D1 generated columns documentation #14579

ciw1973 opened this issue May 15, 2024 · 0 comments · May be fixed by #14812
Assignees
Labels
content:edit Request for content edits documentation Documentation edits product:d1 D1: https://developers.cloudflare.com/d1/

Comments

@ciw1973
Copy link

ciw1973 commented May 15, 2024

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.

@ciw1973 ciw1973 added content:edit Request for content edits documentation Documentation edits labels May 15, 2024
@github-actions github-actions bot added the product:d1 D1: https://developers.cloudflare.com/d1/ label May 15, 2024
@Maddy-Cloudflare Maddy-Cloudflare changed the title Incorrect example code in D1 generated columns documentation [D1] Incorrect example code in D1 generated columns documentation May 15, 2024
@harshil1712 harshil1712 linked a pull request May 29, 2024 that will close this issue
@kodster28 kodster28 linked a pull request May 29, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content:edit Request for content edits documentation Documentation edits product:d1 D1: https://developers.cloudflare.com/d1/
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants