mirror of
				https://github.com/apache/datafusion-sqlparser-rs.git
				synced 2025-10-30 23:07:04 +00:00 
			
		
		
		
	Support EXECUTE ... USING for Postgres (#1153)
				
					
				
			This commit is contained in:
		
							parent
							
								
									9db9d22480
								
							
						
					
					
						commit
						68b52a4ad6
					
				
					 3 changed files with 52 additions and 4 deletions
				
			
		|  | @ -2404,11 +2404,15 @@ pub enum Statement { | |||
|     /// Note: this is a PostgreSQL-specific statement.
 | ||||
|     Deallocate { name: Ident, prepare: bool }, | ||||
|     /// ```sql
 | ||||
|     /// EXECUTE name [ ( parameter [, ...] ) ]
 | ||||
|     /// EXECUTE name [ ( parameter [, ...] ) ] [USING <expr>]
 | ||||
|     /// ```
 | ||||
|     ///
 | ||||
|     /// Note: this is a PostgreSQL-specific statement.
 | ||||
|     Execute { name: Ident, parameters: Vec<Expr> }, | ||||
|     Execute { | ||||
|         name: Ident, | ||||
|         parameters: Vec<Expr>, | ||||
|         using: Vec<Expr>, | ||||
|     }, | ||||
|     /// ```sql
 | ||||
|     /// PREPARE name [ ( data_type [, ...] ) ] AS statement
 | ||||
|     /// ```
 | ||||
|  | @ -3824,11 +3828,18 @@ impl fmt::Display for Statement { | |||
|                 prepare = if *prepare { "PREPARE " } else { "" }, | ||||
|                 name = name, | ||||
|             ), | ||||
|             Statement::Execute { name, parameters } => { | ||||
|             Statement::Execute { | ||||
|                 name, | ||||
|                 parameters, | ||||
|                 using, | ||||
|             } => { | ||||
|                 write!(f, "EXECUTE {name}")?; | ||||
|                 if !parameters.is_empty() { | ||||
|                     write!(f, "({})", display_comma_separated(parameters))?; | ||||
|                 } | ||||
|                 if !using.is_empty() { | ||||
|                     write!(f, " USING {}", display_comma_separated(using))?; | ||||
|                 }; | ||||
|                 Ok(()) | ||||
|             } | ||||
|             Statement::Prepare { | ||||
|  |  | |||
|  | @ -8948,7 +8948,20 @@ impl<'a> Parser<'a> { | |||
|             self.expect_token(&Token::RParen)?; | ||||
|         } | ||||
| 
 | ||||
|         Ok(Statement::Execute { name, parameters }) | ||||
|         let mut using = vec![]; | ||||
|         if self.parse_keyword(Keyword::USING) { | ||||
|             using.push(self.parse_expr()?); | ||||
| 
 | ||||
|             while self.consume_token(&Token::Comma) { | ||||
|                 using.push(self.parse_expr()?); | ||||
|             } | ||||
|         }; | ||||
| 
 | ||||
|         Ok(Statement::Execute { | ||||
|             name, | ||||
|             parameters, | ||||
|             using, | ||||
|         }) | ||||
|     } | ||||
| 
 | ||||
|     pub fn parse_prepare(&mut self) -> Result<Statement, ParserError> { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jonathan Lehto
						Jonathan Lehto