TABLE_EXISTS

更新时间:
复制 MD 格式

Checks whether a specified table exists in MaxCompute.

Syntax

boolean table_exists(string <table_name>)

Parameters

table_name: required. The name of the table to check. This parameter is of the STRING type.

  • To check a table in a different project, use the format <project_name>.<table_name> (for example, my_proj.my_table).

  • If you omit the project name, the function checks the current project.

Return value

Returns a BOOLEAN value:

  • True: the specified table exists.

  • False: the specified table does not exist.

Usage notes

  • The function checks tables in the current project by default. To check a table in another project, prefix the table name with the project name.

  • Use this function in a SELECT expression or as part of a conditional expression such as IF().

Examples

The following example uses table_exists inside an IF() expression to select from two different columns based on whether table abd exists. If the table exists, col1 is returned; otherwise, col2 from table src is returned. This pattern lets you write queries that are resilient to optional tables.

select if(table_exists('abd'), col1, col2) from src;

Related functions

For more information, see Other functions.