mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-22 23:14:07 +00:00
feat: comment and alter column support (#381)
* feat: add support for postgresql comment keyword * feat: add alter column and rename constraint
This commit is contained in:
parent
823635d2fc
commit
9569d1b215
6 changed files with 355 additions and 3 deletions
|
@ -263,6 +263,50 @@ fn parse_create_table_constraints_only() {
|
|||
};
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_alter_table_constraints_rename() {
|
||||
match pg().verified_stmt("ALTER TABLE tab RENAME CONSTRAINT old_name TO new_name") {
|
||||
Statement::AlterTable {
|
||||
name,
|
||||
operation: AlterTableOperation::RenameConstraint { old_name, new_name },
|
||||
} => {
|
||||
assert_eq!("tab", name.to_string());
|
||||
assert_eq!(old_name.to_string(), "old_name");
|
||||
assert_eq!(new_name.to_string(), "new_name");
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_alter_table_alter_column() {
|
||||
pg().one_statement_parses_to(
|
||||
"ALTER TABLE tab ALTER COLUMN is_active TYPE TEXT USING 'text'",
|
||||
"ALTER TABLE tab ALTER COLUMN is_active SET DATA TYPE TEXT USING 'text'",
|
||||
);
|
||||
|
||||
match pg()
|
||||
.verified_stmt("ALTER TABLE tab ALTER COLUMN is_active SET DATA TYPE TEXT USING 'text'")
|
||||
{
|
||||
Statement::AlterTable {
|
||||
name,
|
||||
operation: AlterTableOperation::AlterColumn { column_name, op },
|
||||
} => {
|
||||
assert_eq!("tab", name.to_string());
|
||||
assert_eq!("is_active", column_name.to_string());
|
||||
let using_expr = Expr::Value(Value::SingleQuotedString("text".to_string()));
|
||||
assert_eq!(
|
||||
op,
|
||||
AlterColumnOperation::SetDataType {
|
||||
data_type: DataType::Text,
|
||||
using: Some(using_expr),
|
||||
}
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_create_table_if_not_exists() {
|
||||
let sql = "CREATE TABLE IF NOT EXISTS uk_cities ()";
|
||||
|
@ -749,6 +793,47 @@ fn test_transaction_statement() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_comments() {
|
||||
match pg().verified_stmt("COMMENT ON COLUMN tab.name IS 'comment'") {
|
||||
Statement::Comment {
|
||||
object_type,
|
||||
object_name,
|
||||
comment: Some(comment),
|
||||
} => {
|
||||
assert_eq!("comment", comment);
|
||||
assert_eq!("tab.name", object_name.to_string());
|
||||
assert_eq!(CommentObject::Column, object_type);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
match pg().verified_stmt("COMMENT ON TABLE public.tab IS 'comment'") {
|
||||
Statement::Comment {
|
||||
object_type,
|
||||
object_name,
|
||||
comment: Some(comment),
|
||||
} => {
|
||||
assert_eq!("comment", comment);
|
||||
assert_eq!("public.tab", object_name.to_string());
|
||||
assert_eq!(CommentObject::Table, object_type);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
match pg().verified_stmt("COMMENT ON TABLE public.tab IS NULL") {
|
||||
Statement::Comment {
|
||||
object_type,
|
||||
object_name,
|
||||
comment: None,
|
||||
} => {
|
||||
assert_eq!("public.tab", object_name.to_string());
|
||||
assert_eq!(CommentObject::Table, object_type);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn pg() -> TestedDialects {
|
||||
TestedDialects {
|
||||
dialects: vec![Box::new(PostgreSqlDialect {})],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue