Merge branch 'main' into operator-extension

This commit is contained in:
Luca Cappelletti 2025-11-18 12:52:32 +01:00 committed by GitHub
commit b7692b34ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 1 deletions

View file

@ -5531,7 +5531,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.

View file

@ -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;'";