DerekStride / tree-sitter-sql

SQL grammar for tree-sitter
http://derek.stride.host/tree-sitter-sql/
MIT License
155 stars 52 forks source link

WIP: add multiple alter statements add once (t-sql) #144

Closed matthias-Q closed 1 year ago

matthias-Q commented 1 year ago

Closes #135

This is an attempt to allow for multiple alter table add statements, as it is supported by T-SQL.

This does not work at the moment. I need a right precedence on the repeated section for at the add_column node, but this breaks the _alter_specification one hierarchy level up. I have currently not solution for this problem. @DerekStride, do you have an idea? The issue is that there can be multiple _alter_specification that are separated by commas, same as the _inner_add_column node that I have added.

Reference: https://learn.microsoft.com/de-de/sql/t-sql/statements/alter-table-transact-sql?view=sql-server-ver16

dmfay commented 1 year ago

t-sql also allows for adding a constraint without saying the word constraint, so maybe the thing to do here is to have a general add rule (and possibly the other verbs) that offers a choice between a seq of column definitions or a seq of constraint definitions?

matthias-Q commented 1 year ago

Thanks, @dmfay for the suggestion. I will try this later today

matthias-Q commented 1 year ago

@dmfay I have issues fixing the test alter.txt L428

ALTER TABLE IF EXISTS my_table
  ADD COLUMN IF NOT EXISTS val4 DATE,
  ALTER COLUMN val5 DROP NOT NULL, -- comment, ignore me!
  RENAME COLUMN val6 TO val7,
  DROP COLUMN IF EXISTS val8;

I have checked this statement in Postgres and Mysql and in both dialects it is not valid. The rename is the issue. Is this a bug in our implementation, or is is valid in another dialect?

This is very confusing. When just running the alter table with only the renaming part, if works fine.

dmfay commented 1 year ago

@dmfay I have issues fixing the test alter.txt L428

ALTER TABLE IF EXISTS my_table
  ADD COLUMN IF NOT EXISTS val4 DATE,
  ALTER COLUMN val5 DROP NOT NULL, -- comment, ignore me!
  RENAME COLUMN val6 TO val7,
  DROP COLUMN IF EXISTS val8;

I have checked this statement in Postgres and Mysql and in both dialects it is not valid. The rename is the issue. Is this a bug in our implementation, or is is valid in another dialect?

This is very confusing. When just running the alter table with only the renaming part, if works fine.

It looks like that was added here along with enabling more combinations of actions under alter table for Postgres, but you're right, Postgres' alter table allows column renames only as a single action. I don't know if any other dialects do allow it as one of multiple actions.

matthias-Q commented 1 year ago

Closed by #175