The load utility can be used to load data into a table containing (non-identity) generated columns. It does not, however, currently support the generation of non-identity column values within the utility, so loading into a table with such columns will always leave the table in check pending state. To take the table out of check pending state and force the generation of values, issue:
SET INTEGRITY FOR tablename IMMEDIATE CHECKED FORCE GENERATED;
To accept whatever values were loaded, issue:
SET INTEGRITY FOR tablename GENERATED COLUMN IMMEDIATE UNCHECKED;
If no generated column-related file type modifiers are used, the load utility works according to the following rules:
Three (mutually exclusive) file type modifiers are supported by the load utility to simplify its use with tables that contain generated columns:
create table table1 (c1 int, c2 int, g1 int generated always as (c1 + c2), g2 int generated always as (2 * c1), c3 char(1))
A user may want to load TABLE1 with data from a file (load.del) that has been exported from a table that does not have any generated columns. The following is an example of such a file:
1, 5, J 2, 6, K 3, 7, I
One way to load this file would be to explicitly list the columns to be loaded through the LOAD command as follows:
db2 load from load.del of del replace into table1 (c1, c2, c3)
For a table with many columns, however, this syntax may be cumbersome and prone to error. An alternate method of loading the file is to use the generatedmissing file type modifier as follows:
db2 load from load.del of del modified by generatedmissing replace into table1
1, 5, 10, 15, J 2, 6, 11, 16, K 3, 7, 12, 17, I
The user-supplied, non-NULL values of 10, 11, and 12 (for g1), and 15, 16, and 17 (for g2) result in the row being rejected (SQL3550W). To avoid this, the user could issue the following LOAD command:
db2 load from load.del of del method P(1, 2, 5) replace into table1 (c1, c2, c3)
Again, this approach may be cumbersome and prone to error if the table has many columns. The generatedignore modifier simplifies the syntax as follows:
db2 load from load.del of del modified by generatedignore replace into table1