Purpose
This function returns the maximum value of the partitioning key among the partitions that contain data in a partitioned table.
Note
This function is supported starting from OceanBase Database V4.4.2 BP3.
Limitations and considerations
- The caller must have SELECT object privileges on the target table (Oracle-compatible mode checks object-level privileges). Otherwise, the call fails.
- Table names in parameters must be constants (string literals that can be determined during parsing). Variables or non-constant expressions are not supported as table name parameters.
- The table to be queried must be a partitioned table, and the partition type must be RANGE or LIST.
- The table to be queried must be an internal table. External tables and DBLink are not supported.
- Only a single-column partitioning key is supported; a multi-column partitioning key is not supported.
- Expression partitioning is not supported. If the partitioning key is not a direct reference to a single column but an expression in the partition definition,
MAX_PTcannot be used. - For a subpartitioned table, only the values of the first-level partitions are returned.
- If all partitions are empty, NULL is returned.
- If different partition values exist within the same partition, the result of
MAX_PTisundefined, and a value from any row in that partition will be returned.
Syntax
MAX_PT('[schema_name.]table_name')
Parameters
Notice
In Oracle-compatible mode, schema names and table names are **case-sensitive** and must match the names stored in the data dictionary. Objects created without double quotes are typically stored in uppercase in the dictionary; identifiers created with double quotes are stored in the case used when they were created, and the string must match exactly when invoking them.
schema_name: Optional. The name of the schema that contains the table. If not specified, the table is in the default schema of the current session. You can also use the'schema_name.table_name'format in the parameter string (separated by at most one.).table_name: The name of the table.
Return type
Returns the maximum partition value (compared by using the max() logic) among the partitions that contain data. The data type is the same as the partitioning key type.
Examples
Create a partitioned table named
test_tbl1.obclient> CREATE TABLE test_tbl1 (col1 INT, col2 INT, col3 INT) PARTITION BY LIST (col1) ( PARTITION P0 VALUES (1), PARTITION P1 VALUES (2), PARTITION P2 VALUES (3), PARTITION P3 VALUES (4) );Insert test data.
obclient> INSERT INTO test_tbl1 VALUES (1,1,1), (2,2,2), (3,3,3), (4,4,4), (1,1,2), (2,2,2);The return result is as follows:
Query OK, 6 rows affected Records: 6 Duplicates: 0 Warnings: 0View the maximum value of the partitioning key for the partition containing data in table
test_tbl1.obclient> SELECT MAX_PT('TEST_TBL1') FROM DUAL;The return result is as follows:
+---------------------+ | MAX_PT('TEST_TBL1') | +---------------------+ | 4 | +---------------------+ 1 row in set