Skip to content

Commit d76f5dd

Browse files
committed
Code review comments
1 parent 16639bc commit d76f5dd

File tree

6 files changed

+8
-35
lines changed

6 files changed

+8
-35
lines changed

src/ast/ddl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ pub enum AlterColumnOperation {
893893
data_type: DataType,
894894
/// PostgreSQL specific
895895
using: Option<Expr>,
896-
/// Whether the statement included the optional `SET DATA` keywords
896+
/// Set to true if the statement includes the `SET DATA TYPE` keywords
897897
had_set: bool,
898898
},
899899

src/dialect/mod.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,18 +1061,11 @@ pub trait Dialect: Debug + Any {
10611061
false
10621062
}
10631063

1064-
/// Returns true if the dialect supports `ALTER TABLE tbl ALTER COLUMN col TYPE <type>`
1065-
/// without specifying `SET DATA` before `TYPE`.
1066-
///
1067-
/// - [Redshift](https://docs.aws.amazon.com/redshift/latest/dg/r_ALTER_TABLE.html#r_ALTER_TABLE-synopsis)
1068-
/// - [PostgreSQL](https://www.postgresql.org/docs/current/sql-altertable.html)
1069-
fn supports_alter_column_type_without_set(&self) -> bool {
1070-
false
1071-
}
1072-
1073-
/// Returns true if the dialect supports `ALTER TABLE tbl ALTER COLUMN col SET DATA TYPE <type> USING <exp>`
1074-
///
1075-
/// - [PostgreSQL](https://www.postgresql.org/docs/current/sql-altertable.html)
1064+
/// Returns true if the dialect supports the `USING` clause in an `ALTER COLUMN` statement.
1065+
/// Example:
1066+
/// ```sql
1067+
/// ALTER TABLE tbl ALTER COLUMN col SET DATA TYPE <type> USING <exp>`
1068+
/// ```
10761069
fn supports_alter_column_type_using(&self) -> bool {
10771070
false
10781071
}

src/dialect/postgresql.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,6 @@ impl Dialect for PostgreSqlDialect {
259259
true
260260
}
261261

262-
fn supports_alter_column_type_without_set(&self) -> bool {
263-
true
264-
}
265-
266262
fn supports_alter_column_type_using(&self) -> bool {
267263
true
268264
}

src/dialect/redshift.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,4 @@ impl Dialect for RedshiftSqlDialect {
129129
fn supports_string_literal_backslash_escape(&self) -> bool {
130130
true
131131
}
132-
133-
fn supports_alter_column_type_without_set(&self) -> bool {
134-
true
135-
}
136132
}

src/parser/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8736,9 +8736,7 @@ impl<'a> Parser<'a> {
87368736
AlterColumnOperation::DropDefault {}
87378737
} else if self.parse_keywords(&[Keyword::SET, Keyword::DATA, Keyword::TYPE]) {
87388738
self.parse_set_data_type(true)?
8739-
} else if self.dialect.supports_alter_column_type_without_set()
8740-
&& self.parse_keyword(Keyword::TYPE)
8741-
{
8739+
} else if self.parse_keyword(Keyword::TYPE) {
87428740
self.parse_set_data_type(false)?
87438741
} else if self.parse_keywords(&[Keyword::ADD, Keyword::GENERATED]) {
87448742
let generated_as = if self.parse_keyword(Keyword::ALWAYS) {

tests/sqlparser_common.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5063,17 +5063,7 @@ fn parse_alter_table_alter_column_type() {
50635063
}
50645064
_ => unreachable!(),
50655065
}
5066-
5067-
let dialects = all_dialects_where(|d| d.supports_alter_column_type_without_set());
5068-
dialects.verified_stmt(&format!("{alter_stmt} ALTER COLUMN is_active TYPE TEXT"));
5069-
5070-
let dialects = all_dialects_except(|d| d.supports_alter_column_type_without_set());
5071-
let res =
5072-
dialects.parse_sql_statements(&format!("{alter_stmt} ALTER COLUMN is_active TYPE TEXT"));
5073-
assert_eq!(
5074-
ParserError::ParserError("Expected: SET/DROP NOT NULL, SET DEFAULT, or SET DATA TYPE after ALTER COLUMN, found: TYPE".to_string()),
5075-
res.unwrap_err()
5076-
);
5066+
verified_stmt(&format!("{alter_stmt} ALTER COLUMN is_active TYPE TEXT"));
50775067

50785068
let dialects = all_dialects_where(|d| d.supports_alter_column_type_using());
50795069
dialects.verified_stmt(&format!(

0 commit comments

Comments
 (0)