File tree Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ pub enum DataType {
4949 ///
5050 /// [PostgreSQL]: https://www.postgresql.org/docs/15/sql-createfunction.html
5151 /// [MsSQL]: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-function-transact-sql?view=sql-server-ver16#c-create-a-multi-statement-table-valued-function
52- Table ( Vec < ColumnDef > ) ,
52+ Table ( Option < Vec < ColumnDef > > ) ,
5353 /// Table type with a name, e.g. CREATE FUNCTION RETURNS @result TABLE(...).
5454 NamedTable (
5555 /// Table name.
@@ -724,12 +724,14 @@ impl fmt::Display for DataType {
724724 DataType :: Unspecified => Ok ( ( ) ) ,
725725 DataType :: Trigger => write ! ( f, "TRIGGER" ) ,
726726 DataType :: AnyType => write ! ( f, "ANY TYPE" ) ,
727- DataType :: Table ( fields) => {
728- if fields . is_empty ( ) {
729- return write ! ( f, "TABLE" ) ;
727+ DataType :: Table ( fields) => match fields {
728+ Some ( fields ) => {
729+ write ! ( f, "TABLE({})" , display_comma_separated ( fields ) )
730730 }
731- write ! ( f, "TABLE({})" , display_comma_separated( fields) )
732- }
731+ None => {
732+ write ! ( f, "TABLE" )
733+ }
734+ } ,
733735 DataType :: NamedTable ( name, fields) => {
734736 write ! ( f, "{} TABLE ({})" , name, display_comma_separated( fields) )
735737 }
Original file line number Diff line number Diff line change @@ -5220,9 +5220,19 @@ impl<'a> Parser<'a> {
52205220 p.peek_token().span.start
52215221 )?
52225222 };
5223+
5224+ if table_column_defs.is_none()
5225+ || table_column_defs.clone().is_some_and(|tcd| tcd.is_empty())
5226+ {
5227+ parser_err!(
5228+ "Expected table column definitions after TABLE keyword",
5229+ p.peek_token().span.start
5230+ )?
5231+ }
5232+
52235233 Ok(DataType::NamedTable(
52245234 ObjectName(vec![ObjectNamePart::Identifier(return_table_name)]),
5225- table_column_defs.clone(),
5235+ table_column_defs.clone().unwrap() ,
52265236 ))
52275237 })?;
52285238
@@ -9817,10 +9827,10 @@ impl<'a> Parser<'a> {
98179827 }
98189828 Keyword::TABLE => {
98199829 if self.peek_token() != Token::LParen {
9820- Ok(DataType::Table(Vec::<ColumnDef>::new() ))
9830+ Ok(DataType::Table(None ))
98219831 } else {
98229832 let columns = self.parse_returns_table_columns()?;
9823- Ok(DataType::Table(columns))
9833+ Ok(DataType::Table(Some( columns) ))
98249834 }
98259835 }
98269836 Keyword::SIGNED => {
You can’t perform that action at this time.
0 commit comments