mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-30 10:47:22 +00:00
Support specifying ASC/DESC in index columns (#249)
...by reusing `OrderByExpr` for `columns` in `Statement::CreateIndex`. This supports SQLite's indexed-column syntax https://www.sqlite.org/syntax/indexed-column.html MSSQL's (`ON <object> ( column [ ASC | DESC ] [ ,...n ] )`) https://docs.microsoft.com/en-us/sql/t-sql/statements/create-index-transact-sql?view=sql-server-ver15 And most of PostgreSQL syntax (except for opclass): `( { column_name | ( expression ) } [ COLLATE collation ] [ opclass ] [ ASC | DESC ] [ NULLS { FIRST | LAST } ] [, ...] )` https://www.postgresql.org/docs/12/sql-createindex.html
This commit is contained in:
parent
9e7e30282e
commit
4452f9bad1
3 changed files with 18 additions and 5 deletions
|
@ -3152,8 +3152,19 @@ fn ensure_multiple_dialects_are_tested() {
|
|||
|
||||
#[test]
|
||||
fn parse_create_index() {
|
||||
let sql = "CREATE UNIQUE INDEX IF NOT EXISTS idx_name ON test(name,age)";
|
||||
let ident_vec = vec![Ident::new("name"), Ident::new("age")];
|
||||
let sql = "CREATE UNIQUE INDEX IF NOT EXISTS idx_name ON test(name,age DESC)";
|
||||
let indexed_columns = vec![
|
||||
OrderByExpr {
|
||||
expr: Expr::Identifier(Ident::new("name")),
|
||||
asc: None,
|
||||
nulls_first: None,
|
||||
},
|
||||
OrderByExpr {
|
||||
expr: Expr::Identifier(Ident::new("age")),
|
||||
asc: Some(false),
|
||||
nulls_first: None,
|
||||
},
|
||||
];
|
||||
match verified_stmt(sql) {
|
||||
Statement::CreateIndex {
|
||||
name,
|
||||
|
@ -3164,7 +3175,7 @@ fn parse_create_index() {
|
|||
} => {
|
||||
assert_eq!("idx_name", name.to_string());
|
||||
assert_eq!("test", table_name.to_string());
|
||||
assert_eq!(ident_vec, columns);
|
||||
assert_eq!(indexed_columns, columns);
|
||||
assert_eq!(true, unique);
|
||||
assert_eq!(true, if_not_exists)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue