Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/dialect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,12 @@ pub trait Dialect: Debug + Any {
false
}

/// Returns true if this dialect supports `PROC` as an abbreviation for
/// `PROCEDURE` in a `CREATE` statement.
fn supports_create_proc_syntax(&self) -> bool {
false
}

/// Returns true if the dialect accepts a comma-separated list of table-level
/// options placed between the table name and the column-list parenthesis, e.g.
///
Expand Down
4 changes: 4 additions & 0 deletions src/dialect/mssql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ impl Dialect for MsSqlDialect {
true
}

fn supports_create_proc_syntax(&self) -> bool {
true
}

fn supports_connect_by(&self) -> bool {
true
}
Expand Down
1 change: 1 addition & 0 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,7 @@ define_keywords!(
PRINT,
PRIOR,
PRIVILEGES,
PROC,
PROCEDURE,
PROCESSLIST,
PROFILE,
Expand Down
4 changes: 3 additions & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5334,7 +5334,9 @@ impl<'a> Parser<'a> {
self.parse_create_collation().map(Into::into)
} else if self.parse_keyword(Keyword::TYPE) {
self.parse_create_type()
} else if self.parse_keyword(Keyword::PROCEDURE) {
} else if self.parse_keyword(Keyword::PROCEDURE)
|| self.dialect.supports_create_proc_syntax() && self.parse_keyword(Keyword::PROC)
{
self.parse_create_procedure(or_alter)
} else if self.parse_keyword(Keyword::CONNECTOR) {
self.parse_create_connector().map(Into::into)
Expand Down
17 changes: 17 additions & 0 deletions tests/sqlparser_mssql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2925,3 +2925,20 @@ fn parse_mssql_money_constants() {
expr_from_projection(only(&select.projection)),
);
}

#[test]
fn parse_create_proc() {
ms().one_statement_parses_to(
"CREATE PROC test AS BEGIN SELECT 1; END",
"CREATE PROCEDURE test AS BEGIN SELECT 1; END",
);
ms().one_statement_parses_to(
"CREATE OR ALTER PROC test AS BEGIN SELECT 1; END",
"CREATE OR ALTER PROCEDURE test AS BEGIN SELECT 1; END",
);

TestedDialects::new(vec![Box::new(GenericDialect {})])
.parse_sql_statements("CREATE PROC test AS BEGIN SELECT 1; END")
.expect_err("PROC should remain MSSQL-specific");
ms_and_generic().verified_stmt("SELECT proc FROM jobs");
}