Skip to content

Conversation

@r1b
Copy link

@r1b r1b commented Nov 8, 2025

Using the DEFAULT variant of the CREATE FUNCTION default argument syntax causes a parse error with unnamed arguments. The proposed fix skips the logic to disambiguate argname argtype from argtype when the DEFAULT keyword is detected. IIUC, this is safe because argname and argtype can only take on the name DEFAULT when quoted.

e.g, in postgres this is allowed:

CREATE DOMAIN "DEFAULT" AS int;
CREATE FUNCTION add(INTEGER, "DEFAULT" "DEFAULT" DEFAULT 1) RETURNS INTEGER LANGUAGE SQL AS 'select $1 + $2;';

But "DEFAULT" (the argname) and "DEFAULT" (the argtype) cannot appear unquoted

Ref: apache/datafusion#18450 (comment)

@r1b
Copy link
Author

r1b commented Nov 8, 2025

Please let me know if there is a better place for a more general fix. It seems like adding DEFAULT to RESERVED_FOR_IDENTIFIER might do the trick be necessary as well, but not sure if this is appropriate in all supported dialects.

return self.expected("a name or type", token.clone());
}
// We ensure that the token is a `Word` token, and not other special tokens.
if !matches!(token.token, Token::Word(_)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if !matches!(token.token, Token::Word(_)) {
if self.peek_keyword(DEFAULT) || !matches!(token.token, Token::Word(_)) {

thinking we can simplify the introduced if statement by doing the check here instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't we return a Result<_, ParserError> from parse_function_arg in this case? I was thinking we do still need to continue on to parse the default_expr. I'll take a closer look.

I agree that the nesting is not ideal in any case, maybe another option would be to push this check into maybe_parse above?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah indeed, I misread that block as happening inside of the maybe_parse. Yes the intent would be to ideally do the check in the maybe_parse I think

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a stab at this in 3fc3094

@r1b r1b force-pushed the fix/create-function-unnamed-default branch from 4065072 to 624c0f7 Compare November 12, 2025 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants