DATAPARTITIONNUM scalar function
The DATAPARTITIONNUM function returns the sequence number (SYSDATAPARTITIONS.SEQNO) of the data partition in which the row resides.
The schema is SYSIBM.
-
column-name
- The qualified or unqualified name of any column in the table. Because row-level information is
returned, the result is the same regardless of which column is specified. The column can have any
data type.
If the column is a column of a view, the expression for the column in the view must reference a column of the underlying base table, and the view must be deletable. A nested or common table expression follows the same rules as a view.
Result
The data type of the result is INTEGER and is never null.
Data partitions are sorted by range, and sequence numbers start at 0. For example, the DATAPARTITIONNUM function returns 0 for a row that resides in the data partition with the lowest range.
Notes
- This function cannot be used as a source function when creating a user-defined function. Because the function accepts any data type as an argument, it is not necessary to create additional signatures to support user-defined distinct types.
- The DATAPARTITIONNUM function cannot be used within check constraints or in the definition of generated columns (SQLSTATE 42881). The DATAPARTITIONNUM function cannot be used in a materialized query table (MQT) definition (SQLSTATE 428EC).
- The DATAPARTITIONNUM function cannot be used as part of an expression-based key in a CREATE INDEX statement.
Examples
- Example 1: Retrieve the sequence number of the data partition
in which the row for EMPLOYEE.EMPNO resides.
SELECT DATAPARTITIONNUM (EMPNO) FROM EMPLOYEE
- Example 2: To convert a sequence number that is returned
by DATAPARTITIONNUM (for example, 0) to a data partition name that
can be used in other SQL statements (such as ALTER TABLE...DETACH
PARTITION), you can query the SYSCAT.DATAPARTITIONS catalog view.
Include the SEQNO obtained from DATAPARTITIONNUM in the WHERE clause,
as shown in the following example.
results in the value 'PART0'.SELECT DATAPARTITIONNAME FROM SYSCAT.DATAPARTITIONS WHERE TABNAME = 'EMPLOYEE' AND SEQNO = 0