MEMORY_TABLE table function
The MEMORY_TABLE table function provides fast batch ingestion of streaming workloads into Db2. Table data is transferred to the Db2 server in binary large object (BLOB) format, and rows are created by the table function from the transferred data.
Syntax
The schema is SYSPROC.
The following INSERT statement is used to call the table function and create the rows in a target
database
table:
INSERT into memtest() SELECT from table(SYSPROC.MEMORY_TABLE( CAST (? AS BLOB(2G)) )) AS T()
Table function parameters
- in_mem_table
-
- BLOB(2G) containing the encoded table.
- The result of the function depends on the output specification used during the call to the table function.
Supported source data types
Table data that is transferred does not use a structured format like XML or JSON, to avoid transfer overhead and parsing overhead on the server. The table function transfers tables up to 2GB in size to the server by using the BLOB data type. The data is always transferred by using the client endianess, which must match the server endianness.
Two database code pages are supported:
- 819
- 1208(UTF-8)
Table 1 lists the data types supported
by the MEMORY_TABLE function for the transfer of table data.
Data type | Size | Usage notes |
---|---|---|
SMALLINT | 2 bytes of data |
|
INTEGER | 4 bytes of data |
|
BIGINT | 8 bytes of data |
|
REAL | 4 bytes of data | N/A |
DOUBLE | 8 bytes of data |
|
DECFLOAT(16) | 8 bytes of data | N/A |
DECFLOAT(34) | 16 bytes of data | N/A |
DECIMAL (in packed BCD format) | 8 bytes of data |
|
VARCHAR, | N/A |
|
LONG VARCHAR | N/A | For VARCHAR FOR BIT DATA or VARCHAR data types on non-Unicode databases, the data is not converted. |
VARGRAPHIC | N/A | Data needs to be in UTF-16 format. |
VARBINARY | N/A | N/A |
BOOLEAN | N/A |
|
DATE | N/A |
|
TIME | N/A | N/A |
TIMESTAMP | N/A |
|
Note: The following data types are currently not supported for high speed ingest into Db2® by using the
MEMORY_TABLE function:
- CHAR and GRAPHIC
- LONG VARCHAR, LONG VARGRAPIC
- CLOB, BLOB, and DBCLOB
Authorization
You need to grant EXECUTE privilege on the MEMORY_TABLE table function.
Examples
The following example shows a table INSERT operation using the MEMORY_TABLE function to insert
data into the MEMSET table with the schema (PKID INT, STRINGCOL VARCHAR(255)):
INSERT into memtest(pkid, stringcol) SELECT pkid, stringcol from table(SYSPROC.MEMORY_TABLE( CAST (? AS BLOB(2G)) )) AS T(PKID INT, STRINGCOL VARCHAR(255))