Skip to content

Commit 48c476e

Browse files
Merge branch 'main' into no-whitespace-parser
2 parents f024efc + 1198c1a commit 48c476e

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/parser/mod.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5458,7 +5458,21 @@ impl<'a> Parser<'a> {
54585458
// peek the next token, which if it is another type keyword, then the
54595459
// first token is a name and not a type in itself.
54605460
let data_type_idx = self.get_current_index();
5461-
if let Some(next_data_type) = self.maybe_parse(|parser| parser.parse_data_type())? {
5461+
5462+
// DEFAULT will be parsed as `DataType::Custom`, which is undesirable in this context
5463+
fn parse_data_type_no_default(parser: &mut Parser) -> Result<DataType, ParserError> {
5464+
if parser.peek_keyword(Keyword::DEFAULT) {
5465+
// This dummy error is ignored in `maybe_parse`
5466+
parser_err!(
5467+
"The DEFAULT keyword is not a type",
5468+
parser.peek_token().span.start
5469+
)
5470+
} else {
5471+
parser.parse_data_type()
5472+
}
5473+
}
5474+
5475+
if let Some(next_data_type) = self.maybe_parse(parse_data_type_no_default)? {
54625476
let token = self.token_at(data_type_idx);
54635477

54645478
// We ensure that the token is a `Word` token, and not other special tokens.

tests/sqlparser_postgres.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4509,7 +4509,12 @@ fn parse_create_function_detailed() {
45094509
pg_and_generic().verified_stmt(r#"CREATE OR REPLACE FUNCTION increment(i INTEGER) RETURNS INTEGER LANGUAGE plpgsql AS $$ BEGIN RETURN i + 1; END; $$"#);
45104510
pg_and_generic().verified_stmt(r#"CREATE OR REPLACE FUNCTION no_arg() RETURNS VOID LANGUAGE plpgsql AS $$ BEGIN DELETE FROM my_table; END; $$"#);
45114511
pg_and_generic().verified_stmt(r#"CREATE OR REPLACE FUNCTION return_table(i INTEGER) RETURNS TABLE(id UUID, is_active BOOLEAN) LANGUAGE plpgsql AS $$ BEGIN RETURN QUERY SELECT NULL::UUID, NULL::BOOLEAN; END; $$"#);
4512+
pg_and_generic().one_statement_parses_to(
4513+
"CREATE FUNCTION add(INTEGER, INTEGER DEFAULT 1) RETURNS INTEGER AS 'select $1 + $2;'",
4514+
"CREATE FUNCTION add(INTEGER, INTEGER = 1) RETURNS INTEGER AS 'select $1 + $2;'",
4515+
);
45124516
}
4517+
45134518
#[test]
45144519
fn parse_incorrect_create_function_parallel() {
45154520
let sql = "CREATE FUNCTION add(INTEGER, INTEGER) RETURNS INTEGER LANGUAGE SQL PARALLEL BLAH AS 'select $1 + $2;'";

0 commit comments

Comments
 (0)