Feature/on delete - #197
Conversation
154767b to
9f1d7d1
Compare
matthias-Q
left a comment
There was a problem hiding this comment.
Thanks for the PR. I made some remarks that need to be addressed.
| keyword_cross: _ => make_keyword("cross"), | ||
| keyword_join: _ => make_keyword("join"), | ||
| keyword_lateral: _ => make_keyword("lateral"), | ||
| keyword_natural: _ => make_keyword("natural"), |
There was a problem hiding this comment.
Yes I used my previous MR to avoid conflicts.
| ) | ||
| ), | ||
|
|
||
| natural_join: $ => seq( |
| repeat( | ||
| choice( | ||
| $.join, | ||
| $.natural_join, |
| $.keyword_on, | ||
| $.keyword_delete, | ||
| $.keyword_cascade, | ||
| $._referential_action, |
There was a problem hiding this comment.
this could be combined in one optional block with a choice between keyword_delete and keyword_update. I see no difference between the other parts of the sequence.
9f1d7d1 to
d12b869
Compare
matthias-Q
left a comment
There was a problem hiding this comment.
Thanks for the changes. I double checked the statement in the Postgres documentation and it looks like a small part is missing. Would be nice if you could add this.
| $.keyword_cascade, | ||
| seq( | ||
| $.keyword_set, | ||
| choice($.keyword_null, $.keyword_default), |
There was a problem hiding this comment.
I think set null and set default (this one is missing), can optionally be followed by a column name. In our parser the column name is represented by the object_reference node. (paren_list() of object_reference
https://www.postgresql.org/docs/current/sql-altertable.html (under referential_action)
There was a problem hiding this comment.
You cannot put an object_reference just an identifier:
toto=# create table test1(id integer references test0(id) on delete set null(test.id));
ERROR: syntax error at or near "."
LINE 1: ...d integer references test0(id) on delete set null(test.id));
There was a problem hiding this comment.
Also line 2273 $.ordered_columns should be paren_list($.identifier) at least on postgres.
There was a problem hiding this comment.
This worked for me on postgres 15.3
CREATE TABLE table1 (
id serial PRIMARY KEY,
column_name1 integer,
column_name2 integer
);
CREATE TABLE table2 (
id serial PRIMARY KEY,
table1_id integer REFERENCES table1(id) ON DELETE CASCADE
);
ALTER TABLE table1
DROP CONSTRAINT IF EXISTS table1_column_name1_fkey;
ALTER TABLE table1
ADD CONSTRAINT table1_column_name1_fkey
FOREIGN KEY (column_name1)
REFERENCES table2(id)
ON DELETE SET NULL (column_name1);There was a problem hiding this comment.
You are right about object_reference. This won't work. identifier does work however.
|
@antoineB Thanks for the MR. I have two general remarks: However, we should definitely think about some contribution rules |
No description provided.