tursodatabase / libsql

libSQL is a fork of SQLite that is both Open Source, and Open Contributions.
https://turso.tech/libsql
MIT License
9.54k stars 252 forks source link

adjust ALTER COLUMN parsing #1520

Closed sivukhin closed 2 months ago

sivukhin commented 3 months ago

Context

Current LibSQL code for analyzing ALTER TABLE t ALTER COLUMN x TO x ... just takes raw string after second column name and use it as a column definition with only ; (semicolon) stripped from the end.

This can lead to bad column definition as extra white spaces (like in https://github.com/tursodatabase/libsql/issues/1517) or comments can be prepended to the ALTER TABLE command (for example, ALTER TABLE t4 ALTER COLUMN x TO x INTEGER DEFAULT(-1); -- some explanation should be valid, but with current approach it will be translated to the incorrect SQL: CREATE TABLE t ( x INTEGER DEFAULT(-1); -- some explanation ); note semicolon in the middle of CREATE TABLE expression)

This PR fixes new column sql definition by propagating parsed part of the expression directly from parser

Changes