{"record":{"id":"7214589b7c8e4113","repo":"risingwavelabs/risingwave","slug":"function-definition","errorCode":null,"errorMessage":"function definition","messagePattern":"function definition","errorType":"validation","errorClass":"ParserError","httpStatus":null,"severity":"error","filePath":"src/sqlparser/src/parser.rs","lineNumber":4374,"sourceCode":"            Value::Number(v) => Ok(v),\n            _ => self.expected_at(checkpoint, \"literal number\"),\n        }\n    }\n\n    pub fn parse_literal_u32(&mut self) -> ModalResult<u32> {\n        literal_u32(self)\n    }\n\n    pub fn parse_literal_u64(&mut self) -> ModalResult<u64> {\n        literal_u64(self)\n    }\n\n    pub fn parse_function_definition(&mut self) -> ModalResult<FunctionDefinition> {\n        alt((\n            single_quoted_string.map(FunctionDefinition::SingleQuotedDef),\n            dollar_quoted_string.map(FunctionDefinition::DoubleDollarDef),\n            Self::parse_identifier.map(|i| FunctionDefinition::Identifier(i.value)),\n            fail.expect(\"function definition\"),\n        ))\n        .parse_next(self)\n    }\n\n    /// Parse a literal string\n    pub fn parse_literal_string(&mut self) -> ModalResult<String> {\n        let checkpoint = *self;\n        let token = self.next_token();\n        match token.token {\n            Token::SingleQuotedString(s) => Ok(s),\n            Token::DollarQuotedString(s) => Ok(s.value),\n            _ => self.expected_at(checkpoint, \"literal string\"),\n        }\n    }\n\n    /// Parse a SQL datatype (in the context of a CREATE TABLE statement for example)\n    pub fn parse_data_type(&mut self) -> ModalResult<DataType> {\n        parser_v2::data_type(self)","sourceCodeStart":4356,"sourceCodeEnd":4392,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/sqlparser/src/parser.rs#L4356-L4392","documentation":"Raised by `parse_function_definition` when parsing a CREATE FUNCTION ... AS <body> clause. The body must be a single-quoted string, a dollar-quoted string, or an identifier; any other token fails and yields 'expected function definition'. It reports that the function body/language definition after AS was not a recognized form.","triggerScenarios":"Parsing `CREATE FUNCTION f() ... AS <bad-token>` where the body is missing entirely, unquoted, or uses double quotes/parens, e.g. `AS SELECT 1` or `AS \"body\"` or a truncated statement ending at AS.","commonSituations":"Porting UDF definitions from other engines; scripts where the quoted body string lost its quotes through shell escaping or templating; truncated SQL files.","solutions":["Quote the function body as a string: `AS 'body'` or dollar-quoted `AS $$body$$`.","Use a bare identifier if referring to a named definition: `AS my_func_impl`.","Escape/verify quotes survived shell and template processing before executing the DDL."],"exampleFix":"// before\nCREATE FUNCTION f() RETURNS int AS SELECT 1;\n// after\nCREATE FUNCTION f() RETURNS int AS 'SELECT 1';","handlingStrategy":"validation","validationCode":"// function body must be quoted or a bare identifier\nfunction validFunctionDefinition(body) {\n  return /^[A-Za-z_][A-Za-z0-9_]*$/.test(body) || /^'.*'$/.test(body) || /^\\$\\$[\\s\\S]*\\$\\$$/.test(body);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always wrap CREATE FUNCTION bodies in single quotes or dollar quotes.","Beware shell/template escaping stripping quotes from the body.","Test DDL files end-to-end; truncation after AS is a common cause."],"tags":["sql","parser","create-function","syntax"],"backgroundTag":"invalid-argument-format","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}