SHOW Statements

SHOW statements are used to list all catalogs, or list all databases in the current catalog, or list all tables/views in the current catalog and the current database, or list all functions including temp system functions, system functions, temp catalog functions and catalog functions in the current catalog and the current database.

Flink SQL supports the following SHOW statements for now:

  • SHOW CATALOGS
  • SHOW DATABASES
  • SHOW TABLES
  • SHOW VIEWS
  • SHOW FUNCTIONS

Run a SHOW statement

SHOW statements can be executed with the executeSql() method of the TableEnvironment, or executed in SQL CLI. The executeSql() method returns objects for a successful SHOW operation, otherwise will throw an exception.

The following examples show how to run a SHOW statement in TableEnvironment and in SQL CLI.

  1. StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
  2. StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
  3. // show catalogs
  4. tEnv.executeSql("SHOW CATALOGS").print();
  5. // +-----------------+
  6. // | catalog name |
  7. // +-----------------+
  8. // | default_catalog |
  9. // +-----------------+
  10. // show databases
  11. tEnv.executeSql("SHOW DATABASES").print();
  12. // +------------------+
  13. // | database name |
  14. // +------------------+
  15. // | default_database |
  16. // +------------------+
  17. // create a table
  18. tEnv.executeSql("CREATE TABLE my_table (...) WITH (...)");
  19. // show tables
  20. tEnv.executeSql("SHOW TABLES").print();
  21. // +------------+
  22. // | table name |
  23. // +------------+
  24. // | my_table |
  25. // +------------+
  26. // create a view
  27. tEnv.executeSql("CREATE VIEW my_view AS ...");
  28. // show views
  29. tEnv.executeSql("SHOW VIEWS").print();
  30. // +-----------+
  31. // | view name |
  32. // +-----------+
  33. // | my_view |
  34. // +-----------+
  35. // show functions
  36. tEnv.executeSql("SHOW FUNCTIONS").print();
  37. // +---------------+
  38. // | function name |
  39. // +---------------+
  40. // | mod |
  41. // | sha256 |
  42. // | ... |
  43. // +---------------+
  1. val env = StreamExecutionEnvironment.getExecutionEnvironment()
  2. val tEnv = StreamTableEnvironment.create(env)
  3. // show catalogs
  4. tEnv.executeSql("SHOW CATALOGS").print()
  5. // +-----------------+
  6. // | catalog name |
  7. // +-----------------+
  8. // | default_catalog |
  9. // +-----------------+
  10. // show databases
  11. tEnv.executeSql("SHOW DATABASES").print()
  12. // +------------------+
  13. // | database name |
  14. // +------------------+
  15. // | default_database |
  16. // +------------------+
  17. // create a table
  18. tEnv.executeSql("CREATE TABLE my_table (...) WITH (...)")
  19. // show tables
  20. tEnv.executeSql("SHOW TABLES").print()
  21. // +------------+
  22. // | table name |
  23. // +------------+
  24. // | my_table |
  25. // +------------+
  26. // create a view
  27. tEnv.executeSql("CREATE VIEW my_view AS ...")
  28. // show views
  29. tEnv.executeSql("SHOW VIEWS").print()
  30. // +-----------+
  31. // | view name |
  32. // +-----------+
  33. // | my_view |
  34. // +-----------+
  35. // show functions
  36. tEnv.executeSql("SHOW FUNCTIONS").print()
  37. // +---------------+
  38. // | function name |
  39. // +---------------+
  40. // | mod |
  41. // | sha256 |
  42. // | ... |
  43. // +---------------+
  1. settings = EnvironmentSettings.new_instance()...
  2. table_env = StreamTableEnvironment.create(env, settings)
  3. # show catalogs
  4. table_env.execute_sql("SHOW CATALOGS").print()
  5. # +-----------------+
  6. # | catalog name |
  7. # +-----------------+
  8. # | default_catalog |
  9. # +-----------------+
  10. # show databases
  11. table_env.execute_sql("SHOW DATABASES").print()
  12. # +------------------+
  13. # | database name |
  14. # +------------------+
  15. # | default_database |
  16. # +------------------+
  17. # create a table
  18. table_env.execute_sql("CREATE TABLE my_table (...) WITH (...)")
  19. # show tables
  20. table_env.execute_sql("SHOW TABLES").print()
  21. # +------------+
  22. # | table name |
  23. # +------------+
  24. # | my_table |
  25. # +------------+
  26. # create a view
  27. table_env.execute_sql("CREATE VIEW my_view AS ...")
  28. # show views
  29. table_env.execute_sql("SHOW VIEWS").print()
  30. # +-----------+
  31. # | view name |
  32. # +-----------+
  33. # | my_view |
  34. # +-----------+
  35. # show functions
  36. table_env.execute_sql("SHOW FUNCTIONS").print()
  37. # +---------------+
  38. # | function name |
  39. # +---------------+
  40. # | mod |
  41. # | sha256 |
  42. # | ... |
  43. # +---------------+
  1. Flink SQL> SHOW CATALOGS;
  2. default_catalog
  3. Flink SQL> SHOW DATABASES;
  4. default_database
  5. Flink SQL> CREATE TABLE my_table (...) WITH (...);
  6. [INFO] Table has been created.
  7. Flink SQL> SHOW TABLES;
  8. my_table
  9. Flink SQL> CREATE VIEW my_view AS ...;
  10. [INFO] View has been created.
  11. Flink SQL> SHOW VIEWS;
  12. my_view
  13. Flink SQL> SHOW FUNCTIONS;
  14. mod
  15. sha256
  16. ...

Back to top

SHOW CATALOGS

  1. SHOW CATALOGS

Show all catalogs.

SHOW DATABASES

  1. SHOW DATABASES

Show all databases in the current catalog.

SHOW TABLES

  1. SHOW TABLES

Show all tables in the current catalog and the current database.

SHOW VIEWS

  1. SHOW VIEWS

Show all views in the current catalog and the current database.

SHOW FUNCTIONS

  1. SHOW FUNCTIONS

Show all functions including temp system functions, system functions, temp catalog functions and catalog functions in the current catalog and current database.