This is an automated email from the ASF dual-hosted git repository.

github-bot pushed a commit to branch 
gh-readonly-queue/main/pr-2091-4f79997c8efa1c6089ef5795ac8317152205d8c0
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git

commit 7aa902d494d17f75163325ea655e62b9dbae4a92
Author: r1b <[email protected]>
AuthorDate: Tue Nov 18 04:08:39 2025 -0500

    fix: parse error on unnamed arg with default syntax (#2091)
---
 src/parser/mod.rs           | 16 +++++++++++++++-
 tests/sqlparser_postgres.rs |  5 +++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index 0b2158e6..1ab4626f 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -5522,7 +5522,21 @@ impl<'a> Parser<'a> {
         // peek the next token, which if it is another type keyword, then the
         // first token is a name and not a type in itself.
         let data_type_idx = self.get_current_index();
-        if let Some(next_data_type) = self.maybe_parse(|parser| 
parser.parse_data_type())? {
+
+        // DEFAULT will be parsed as `DataType::Custom`, which is undesirable 
in this context
+        fn parse_data_type_no_default(parser: &mut Parser) -> Result<DataType, 
ParserError> {
+            if parser.peek_keyword(Keyword::DEFAULT) {
+                // This dummy error is ignored in `maybe_parse`
+                parser_err!(
+                    "The DEFAULT keyword is not a type",
+                    parser.peek_token().span.start
+                )
+            } else {
+                parser.parse_data_type()
+            }
+        }
+
+        if let Some(next_data_type) = 
self.maybe_parse(parse_data_type_no_default)? {
             let token = self.token_at(data_type_idx);
 
             // We ensure that the token is a `Word` token, and not other 
special tokens.
diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs
index 75d567c1..3bdf6d18 100644
--- a/tests/sqlparser_postgres.rs
+++ b/tests/sqlparser_postgres.rs
@@ -4475,7 +4475,12 @@ fn parse_create_function_detailed() {
     pg_and_generic().verified_stmt(r#"CREATE OR REPLACE FUNCTION increment(i 
INTEGER) RETURNS INTEGER LANGUAGE plpgsql AS $$ BEGIN RETURN i + 1; END; $$"#);
     pg_and_generic().verified_stmt(r#"CREATE OR REPLACE FUNCTION no_arg() 
RETURNS VOID LANGUAGE plpgsql AS $$ BEGIN DELETE FROM my_table; END; $$"#);
     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; $$"#);
+    pg_and_generic().one_statement_parses_to(
+        "CREATE FUNCTION add(INTEGER, INTEGER DEFAULT 1) RETURNS INTEGER AS 
'select $1 + $2;'",
+        "CREATE FUNCTION add(INTEGER, INTEGER = 1) RETURNS INTEGER AS 'select 
$1 + $2;'",
+    );
 }
+
 #[test]
 fn parse_incorrect_create_function_parallel() {
     let sql = "CREATE FUNCTION add(INTEGER, INTEGER) RETURNS INTEGER LANGUAGE 
SQL PARALLEL BLAH AS 'select $1 + $2;'";


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to