@@ -1915,6 +1915,59 @@ fn parse_snowflake_declare_result_set() {
19151915 ) ;
19161916}
19171917
1918+ #[ test]
1919+ fn parse_snowflake_declare_show_payload ( ) {
1920+ fn payload_show ( stmt : Statement ) -> Statement {
1921+ match stmt {
1922+ Statement :: Declare { mut stmts } => {
1923+ assert_eq ! ( 1 , stmts. len( ) ) ;
1924+ let Declare {
1925+ assignment,
1926+ for_query,
1927+ ..
1928+ } = stmts. swap_remove ( 0 ) ;
1929+ let query = match ( assignment, for_query) {
1930+ ( Some ( DeclareAssignment :: Default ( expr) ) , None )
1931+ | ( Some ( DeclareAssignment :: DuckAssignment ( expr) ) , None )
1932+ | ( Some ( DeclareAssignment :: For ( expr) ) , None ) => match * expr {
1933+ Expr :: Subquery ( query) => query,
1934+ other => panic ! ( "expected subquery payload, got {other:?}" ) ,
1935+ } ,
1936+ other => panic ! ( "unexpected declaration payload: {other:?}" ) ,
1937+ } ;
1938+ match * query. body {
1939+ SetExpr :: Show ( show) => show,
1940+ other => panic ! ( "expected SHOW body, got {other:?}" ) ,
1941+ }
1942+ }
1943+ other => panic ! ( "expected DECLARE, got {other:?}" ) ,
1944+ }
1945+ }
1946+
1947+ for sql in [
1948+ "DECLARE res RESULTSET DEFAULT (SHOW TASKS)" ,
1949+ "DECLARE res RESULTSET := (SHOW TASKS LIKE 'foo%')" ,
1950+ "DECLARE cur CURSOR FOR (SHOW TASKS)" ,
1951+ ] {
1952+ let stmt = snowflake ( ) . verified_stmt ( sql) ;
1953+ // The parsed SHOW must be recoverable from the declaration AST.
1954+ assert ! ( matches!( payload_show( stmt) , Statement :: ShowTasks { .. } ) ) ;
1955+ }
1956+
1957+ // The pre-existing parenthesized-SELECT payload is unaffected.
1958+ snowflake ( ) . verified_stmt ( "DECLARE res RESULTSET DEFAULT (SELECT price FROM invoices)" ) ;
1959+ snowflake ( ) . verified_stmt ( "DECLARE cur CURSOR FOR (SELECT id FROM invoices)" ) ;
1960+
1961+ // Under a non-Snowflake dialect the SHOW payload still errors.
1962+ let generic = TestedDialects :: new ( vec ! [ Box :: new( GenericDialect { } ) ] ) ;
1963+ for sql in [
1964+ "DECLARE res RESULTSET DEFAULT (SHOW TASKS)" ,
1965+ "DECLARE cur CURSOR FOR (SHOW TASKS)" ,
1966+ ] {
1967+ assert ! ( generic. parse_sql_statements( sql) . is_err( ) ) ;
1968+ }
1969+ }
1970+
19181971#[ test]
19191972fn parse_snowflake_declare_exception ( ) {
19201973 for ( sql, expected_name, expected_assigned_expr) in [
0 commit comments