@@ -713,6 +713,78 @@ fn parse_alter_table_add_columns() {
713713 }
714714}
715715
716+ #[ test]
717+ fn parse_alter_table_owner_to ( ) {
718+ struct TestCase {
719+ sql : & ' static str ,
720+ expected_owner : Owner ,
721+ }
722+
723+ let test_cases = vec ! [
724+ TestCase {
725+ sql: "ALTER TABLE tab OWNER TO new_owner" ,
726+ expected_owner: Owner :: Ident ( Ident :: new( "new_owner" . to_string( ) ) ) ,
727+ } ,
728+ TestCase {
729+ sql: "ALTER TABLE tab OWNER TO postgres" ,
730+ expected_owner: Owner :: Ident ( Ident :: new( "postgres" . to_string( ) ) ) ,
731+ } ,
732+ TestCase {
733+ sql: "ALTER TABLE tab OWNER TO CREATE" , // treats CREATE as an identifier
734+ expected_owner: Owner :: Ident ( Ident :: new( "CREATE" . to_string( ) ) ) ,
735+ } ,
736+ TestCase {
737+ sql: "ALTER TABLE tab OWNER TO \" new_owner\" " ,
738+ expected_owner: Owner :: Ident ( Ident :: with_quote( '\"' , "new_owner" . to_string( ) ) ) ,
739+ } ,
740+ TestCase {
741+ sql: "ALTER TABLE tab OWNER TO CURRENT_USER" ,
742+ expected_owner: Owner :: CurrentUser ,
743+ } ,
744+ TestCase {
745+ sql: "ALTER TABLE tab OWNER TO CURRENT_ROLE" ,
746+ expected_owner: Owner :: CurrentRole ,
747+ } ,
748+ TestCase {
749+ sql: "ALTER TABLE tab OWNER TO SESSION_USER" ,
750+ expected_owner: Owner :: SessionUser ,
751+ } ,
752+ ] ;
753+
754+ for case in test_cases {
755+ match pg_and_generic ( ) . verified_stmt ( case. sql ) {
756+ Statement :: AlterTable {
757+ name,
758+ if_exists : _,
759+ only : _,
760+ operations,
761+ location : _,
762+ } => {
763+ assert_eq ! ( name. to_string( ) , "tab" ) ;
764+ assert_eq ! (
765+ operations,
766+ vec![ AlterTableOperation :: OwnerTo {
767+ new_owner: case. expected_owner. clone( )
768+ } ]
769+ ) ;
770+ }
771+ _ => unreachable ! ( "Expected an AlterTable statement" ) ,
772+ }
773+ }
774+
775+ let res = pg ( ) . parse_sql_statements ( "ALTER TABLE tab OWNER TO CREATE FOO" ) ;
776+ assert_eq ! (
777+ ParserError :: ParserError ( "Expected: end of statement, found: FOO" . to_string( ) ) ,
778+ res. unwrap_err( )
779+ ) ;
780+
781+ let res = pg ( ) . parse_sql_statements ( "ALTER TABLE tab OWNER TO 4" ) ;
782+ assert_eq ! (
783+ ParserError :: ParserError ( "Expected: CURRENT_USER, CURRENT_ROLE, SESSION_USER or identifier after OWNER TO. sql parser error: Expected: identifier, found: 4" . to_string( ) ) ,
784+ res. unwrap_err( )
785+ ) ;
786+ }
787+
716788#[ test]
717789fn parse_create_table_if_not_exists ( ) {
718790 let sql = "CREATE TABLE IF NOT EXISTS uk_cities ()" ;
0 commit comments