IBM Db2

IBM Db2 is a database that contains relational data. You can add an IBM Db2 data source as an infrastructure component.

watsonx.data on IBM Software Hub

watsonx.data Developer edition

IBM Db2

You can add IBM Db2 as a data source infrastructure component in the following ways:

Create new connection - configuration details

Table 1. Create new connection - configuration details
Field Description
Target persistence

Select the target persistence:

  • watsonx.data instance - The instance console database stores the connection details exclusively.
  • Platform asset catalog - The default catalog in the data platform stores your connection details. If you select Platform asset catalog as the target persistence, you must specify a warehouse name. You can select the Platform asset catalog option only if data platform services are active, a Platform asset catalog exists in the data platform, and you have access to it.
Display name The name of the new infrastructure component.
Database name Enter the name of your database.
Hostname Enter the Hostname.
Port Enter the Port number.
Input method
Note: This field is available only when use of secrets from an external vault (HashiCorp) is configured for your connections.
Choose the credential input method:
  • Enter credential manually
  • Use secret from vault
To use secrets from an external vault, select the Use secret from vault option and complete the following steps:
  1. Click Select secret.
  2. Select one or more secrets and click Select.
Authentication type If you are entering the credentials manually, then choose and enter the Authentication type details:
  • Username and password: Enter the database username and database password.
  • Authentication value: Enter the API key.

If you are using secrets from vault, then select the Username and password or Authentication key from the respective drop-down lists.

Port is SSL enabled Use the toggle switch to enable or disable SSL connection. If enabled,

i. The Upload SSL certificate (.pem, .crt, .cert, or .cer) link is enabled.

ii. Click the Upload SSL certificate (.pem, .crt, .cert, or .cer) link.

iii. Browse the SSL certificate and upload.

If you are using secrets from vault, then select from the Upload SSL certificate drop-down list.

Connection status Click the Test connection link to test the database connection. If the database connection is successful, a success message appears.

Console UI

Associate catalog

Console UI

Select the checkbox to add a catalog for your storage. This catalog is associated with your storage and serves as your query interface with the data stored within.
Catalog name / Name
  • Console UI

    Catalog name: Enter the name of the catalog.
  • Platform UI

    Name: Enter the name of the database associated with your data source. The database serves as your query interface with the data stored within.
Create
  • Click Create to create the data source.

Importing an existing connection

Table 2. Importing an existing connection
Field Description
Select the location of the existing connection

Select from where to import the connection:

  • Select a project on the Import from project tab.
  • Console UI

    Select the connection on the Import from platform catalog tab.
  • Platform UI

    Select the connection on the Import from database tab.
Important: Connections can only be imported from catalogs, databases, or projects that are on the same cluster. Catalogs, databases, or projects created in a different cluster within the data platform cannot be imported.
Select data source Use the dropdown to select a data source from the selected catalog, database, or project.
Target persistence

Select the target persistence:

  • watsonx.data instance - The instance console database stores the connection details exclusively.
  • Platform asset catalog - The default catalog in the data platform stores your connection details. If you select Platform asset catalog as the target persistence, you must specify a warehouse name. You can select the Platform asset catalog option only if data platform services are active, a Platform asset catalog exists in the data platform, and you have access to it.
Display name The name of the new infrastructure component.

Console UI

Associate catalog

Console UI

Select the checkbox to add a catalog for your storage. This catalog is associated with your storage and serves as your query interface with the data stored within.
Catalog name / Name
  • Console UI

    Catalog name: Enter the name of the catalog.
  • Platform UI

    Name: Enter the name of the database associated with your data source and serves as your query interface with the data stored within.
Create Click Create to create the database.
Note: Select IBM Db2 from the Data sources section under the Add component list to add IBM Watson Query.

You can now query the nicknames that are created in IBM Db2 and the virtualized tables from Watson Query instances.

Additional Information

You can perform the following operations for BLOB and CLOB data types for Db2 data source:
  • INSERT
  • CREATE
  • CTAS
  • ALTER
  • DROP
To insert CLOB data type, provide the value directly or cast it explicitly to CLOB data type.
INSERT INTO <table_name> VALUES ('<clob value>', '<other values>');
INSERT INTO <table_name> VALUES (CAST('<clob text>' AS CLOB));
To insert BLOB data, use the cast function with BLOB data type. The corresponding hexadecimal value is inserted into the Db2 data source:
INSERT INTO <table_name> VALUES (CAST('<blob text>' AS BLOB));
Collecting and using statistics for Db2 query optimisation
The IBM Db2 connector uses table and column statistics to perform cost-based optimizations, enabling more efficient query processing based on the actual data in the source. IBM Db2 generates and maintains these statistics, and the connector retrieves them during query planning to improve query performance.

To collect statistics for a table in Db2, run the following command:

CALL SYSPROC.ADMIN_CMD('RUNSTATS ON TABLE table_name');

For more information, see RUNSTATS command.

Limitations for SQL statements

  • ALTER TABLE DROP COLUMN operation is not supported for column-organized tables.
  • DROP TABLE statement is supported only when enabled in the catalog.
  • CREATE VIEW can be used for a table only if that table is in the same catalog.
  • DROP SCHEMA can do RESTRICT by default.
  • For the database-based catalogs, CREATE SCHEMA, CREATE TABLE, DROP SCHEMA, DROP TABLE, DELETE, DROP VIEW, ALTER TABLE, and ALTER SCHEMA statements are not available in the Data manager UI.
  • In the CREATE VIEW statement, column names must be enclosed in double quotes, and their case must match exactly as they are stored in the database, including uppercase, lowercase, or mixed case.
  • The ALTER VIEW RENAME operation is not supported.

Limitations for data types

  • BLOB and CLOB data types support SELECT statement but do not support operations such as equal, like, and in.
  • BINARY data type supports only SELECT statement.
  • When the fields of data type REAL have 6 digits or more in the decimal part with the digits being predominately zero, the values when queried are rounded off. It is observed that the rounding off occurs differently based on the precision of the values. For example, a decimal number 1.654 when rounded to 3-digits after the decimal point are the same. Another example is 10.890009 and 10.89000. It is noticed that 10.89000 is rounded to 10.89, whereas 10.89009 is not rounded off. This is an inherent issue because of the representational limitations of binary floating point formats. This might have a significant impact when querying involves sorting.