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_PTfunction is used. For example, you can useSELECT * FROM table WHERE pt=MAX_PT("table");instead ofSELECT * FROM table WHERE pt = (SELECT MAX(pt) FROM table);.NoteMaxCompute does not provide the
MIN_PTfunction. 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_PTfunction.If all partitions in the table are empty, the
MAX_PTfunction fails to be executed. You must make sure that at least one partition is not empty.OSS external tables also support the
MAX_PTfunction, with behavior consistent with internal tables.
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 created by using the ALTER TABLE statement and the partition does not contain data, 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_PTfunction returns'20120902', and the MaxCompute SQL statement reads data from the20120902partition. Sample statements:SELECT * FROM tbl WHERE pt= MAX_PT('tbl'); -- The preceding statement is equivalent to the following statement: SELECT * FROM tbl WHERE pt= (SELECT MAX(pt) FROM 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.