DROP Statements

    Flink SQL supports the following DROP statements for now:

    • DROP CATALOG
    • DROP TABLE
    • DROP DATABASE
    • DROP VIEW
    • DROP FUNCTION

    Java

    DROP statements can be executed with the method of the TableEnvironment. The executeSql() method returns ‘OK’ for a successful DROP operation, otherwise will throw an exception.

    The following examples show how to run a DROP statement in TableEnvironment.

    Scala

    DROP statements can be executed with the executeSql() method of the TableEnvironment. The executeSql() method returns ‘OK’ for a successful DROP operation, otherwise will throw an exception.

    The following examples show how to run a DROP statement in TableEnvironment.

    Python

    DROP statements can be executed with the execute_sql() method of the TableEnvironment. The execute_sql() method returns ‘OK’ for a successful DROP operation, otherwise will throw an exception.

    The following examples show how to run a DROP statement in TableEnvironment.

    SQL CLI

    DROP statements can be in SQL CLI.

    The following examples show how to run a DROP statement in SQL CLI.

    Java

    1. val tableEnv = TableEnvironment.create(...)
    2. tableEnv.executeSql("CREATE TABLE Orders (`user` BIGINT, product STRING, amount INT) WITH (...)")
    3. // a string array: ["Orders"]
    4. val tables = tableEnv.listTables()
    5. // or tableEnv.executeSql("SHOW TABLES").print()
    6. // drop "Orders" table from catalog
    7. tableEnv.executeSql("DROP TABLE Orders")
    8. // an empty string array
    9. val tables = tableEnv.listTables()
    10. // or tableEnv.executeSql("SHOW TABLES").print()

    Python

    1. table_env = TableEnvironment.create(...)
    2. # a string array: ["Orders"]
    3. tables = table_env.list_tables()
    4. # or table_env.execute_sql("SHOW TABLES").print()
    5. # drop "Orders" table from catalog
    6. table_env.execute_sql("DROP TABLE Orders")
    7. # an empty string array
    8. tables = table_env.list_tables()
    9. # or table_env.execute_sql("SHOW TABLES").print()

    SQL CLI

    DROP CATALOG

    1. DROP CATALOG [IF EXISTS] catalog_name

    Drop a catalog with the given catalog name.

    IF EXISTS

    If the catalog does not exist, nothing happens.

    1. DROP [TEMPORARY] TABLE [IF EXISTS] [catalog_name.][db_name.]table_name

    Drop a table with the given table name. If the table to drop does not exist, an exception is thrown.

    TEMPORARY

    Drop temporary table that has catalog and database namespaces.

    IF EXISTS

    If the table does not exist, nothing happens.

    DROP DATABASE

    Drop a database with the given database name. If the database to drop does not exist, an exception is thrown.

    IF EXISTS

    If the database does not exist, nothing happens.

    RESTRICT

    CASCADE

    Dropping a non-empty database also drops all associated tables and functions.

    1. DROP [TEMPORARY] VIEW [IF EXISTS] [catalog_name.][db_name.]view_name

    Drop a view that has catalog and database namespaces. If the view to drop does not exist, an exception is thrown.

    TEMPORARY

    Drop temporary view that has catalog and database namespaces.

    IF EXISTS

    If the view does not exist, nothing happens.

    MAINTAIN DEPENDENCIES Flink does not maintain dependencies of view by CASCADE/RESTRICT keywords, the current way is producing postpone error message when user tries to use the view under the scenarios like the underlying table of view has been dropped.

    DROP FUNCTION

      Drop a catalog function that has catalog and database namespaces. If the function to drop does not exist, an exception is thrown.

      TEMPORARY

      Drop temporary catalog function that has catalog and database namespaces.

      TEMPORARY SYSTEM

      Drop temporary system function that has no namespace.

      IF EXISTS