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 @@ -5224,9 +5224,19 @@ impl<'a> Parser<'a> {
52245224 p.peek_token().span.start
52255225 )?
52265226 };
5227+
5228+ if table_column_defs.is_none()
5229+ || table_column_defs.clone().is_some_and(|tcd| tcd.is_empty())
5230+ {
5231+ parser_err!(
5232+ "Expected table column definitions after TABLE keyword",
5233+ p.peek_token().span.start
5234+ )?
5235+ }
5236+
52275237 Ok(DataType::NamedTable(
52285238 ObjectName(vec![ObjectNamePart::Identifier(return_table_name)]),
5229- table_column_defs.clone(),
5239+ table_column_defs.clone().unwrap() ,
52305240 ))
52315241 })?;
52325242
@@ -9838,10 +9848,10 @@ impl<'a> Parser<'a> {
98389848 }
98399849 Keyword::TABLE => {
98409850 if self.peek_token() != Token::LParen {
9841- Ok(DataType::Table(Vec::<ColumnDef>::new() ))
9851+ Ok(DataType::Table(None ))
98429852 } else {
98439853 let columns = self.parse_returns_table_columns()?;
9844- Ok(DataType::Table(columns))
9854+ Ok(DataType::Table(Some( columns) ))
98459855 }
98469856 }
98479857 Keyword::SIGNED => {
You can’t perform that action at this time.
0 commit comments