Replying to 4c7b0197e1 in thread FEATURE REQUEST: use of DEFAULT in INSERTs
By Richard Hipp (drh) on 2025-02-15 23:22:45
The original branch for this has been closed and will be abandoned. I found a new way to implement the DEFAULT behavior that is cleaner (read: easier to maintain long-term) and faster. And as far as I can see, it sticks closer to Postgres syntax.
On the default-in-values-2 branch there is code that allows the DEFAULT keyword to appear in following places:
- As a complete term in a VALUES clause on an INSERT or REPLACE statement.
- On the right-hand side of a SET term in an UPDATE statement.
Hence you can say things like:
INSERT INTO t1(e,a,x) VALUES(1,2,3),(4,
DEFAULT,5);
UPDATE t2 SET e=1, a=
DEFAULT, x=random() WHERE id=22;
If the DEFAULT keyword appears anywhere else (other than in the column definition of a CREATE TABLE or ALTER TABLE ADD COLUMN statement of course), then it is a syntax error. DEFAULT cannot be part of a larger expression. This is how Postgres behaves, so I'm guessing that is what the SQL standards require. Correct me if you think the previous sentence is wrong.
I feel like the new branch has a much greater chance of landing on trunk someday. Meanwhile, y'all are all encouraged to try to break it, or to find differences in what the branch does and what PostgreSQL does.