Returns the name of the largest level-1 partition that contains data in a partitioned table and reads the data of this partition. This function determines the largest partition by sorting partitions in alphabetical order.
Usage notes
You can also use a standard SQL statement instead of the statement in which the
MAX_PT
function is used. For example, you can useselect * from table where pt = (select max(pt) from table);
instead ofselect * from table where pt = max_pt("table");
.NoteMaxCompute does not provide the
MIN_PT
function. If you need to obtain the partition that contains the fewest amount of data in a partitioned table, you cannot use the SQL statementselect * from table where pt = min_pt("table");
. Instead, you can use the standard SQL statementselect * from table where pt = (select min(pt) from table);
to achieve a similar effect as theMAX_PT
function.If all partitions in the table are empty, the
MAX_PT
function fails to be executed. You must make sure that at least one partition is not empty.OSS external tables do not support the
MAX_PT
function.
Syntax
max_pt(<table_full_name>)
Parameters
table_full_name: required. A value of the STRING type. This parameter specifies the name of the table. You must have read permissions on the table.
Return value
The name of the largest level-1 partition is returned.
If a partition is added by using the ALTER TABLE
statement and the partition does not contain data, the name of this partition is not returned.
Examples
Example 1: The tbl table is a partitioned table. The partitions in the table are 20120901 and 20120902, both of which contain data. If you execute the following statement, the
MAX_PT
function returns'20120902'
, and the MaxCompute SQL statement reads data from the20120902
partition. Sample statements:select * from tbl where pt=max_pt('myproject.tbl'); -- The preceding statement is equivalent to the following statement: select * from tbl where pt = (select max(pt) from myproject.tbl);
Example 2: If a partitioned table contains multiple levels of partitions, use the standard SQL statement to obtain data from the largest partition. Sample statement:
select * from table where pt1 = (select max(pt1) from table) and pt2 = (select max(pt2) from table where pt1 = (select max(pt1) from table));
Related functions
For more information, see Other functions.