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 @@ -5221,9 +5221,19 @@ impl<'a> Parser<'a> {
52215221 p.peek_token().span.start
52225222 )?
52235223 };
5224+
5225+ if table_column_defs.is_none()
5226+ || table_column_defs.clone().is_some_and(|tcd| tcd.is_empty())
5227+ {
5228+ parser_err!(
5229+ "Expected table column definitions after TABLE keyword",
5230+ p.peek_token().span.start
5231+ )?
5232+ }
5233+
52245234 Ok(DataType::NamedTable(
52255235 ObjectName(vec![ObjectNamePart::Identifier(return_table_name)]),
5226- table_column_defs.clone(),
5236+ table_column_defs.clone().unwrap() ,
52275237 ))
52285238 })?;
52295239
@@ -9835,10 +9845,10 @@ impl<'a> Parser<'a> {
98359845 }
98369846 Keyword::TABLE => {
98379847 if self.peek_token() != Token::LParen {
9838- Ok(DataType::Table(Vec::<ColumnDef>::new() ))
9848+ Ok(DataType::Table(None ))
98399849 } else {
98409850 let columns = self.parse_returns_table_columns()?;
9841- Ok(DataType::Table(columns))
9851+ Ok(DataType::Table(Some( columns) ))
98429852 }
98439853 }
98449854 Keyword::SIGNED => {
You can’t perform that action at this time.
0 commit comments