473,378 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

loading in to generated row change timestamp column

We're trying to take advantage of the new ROW CHANGE TIMESTAMP option.

Here is a simple table:

CREATE TABLE "ACCTASGN"."NUMBER_STATUS" (
"STATUS_CODE" CHAR(1) NOT NULL ,
"STATUS_DESCRIPTION" VARCHAR(40) NOT NULL ,
"LAST_UPDATE" TIMESTAMP NOT NULL
GENERATED ALWAYS FOR EACH ROW
ON UPDATE AS ROW CHANGE TIMESTAMP
);

ALTER TABLE "ACCTASGN"."NUMBER_STATUS"
ADD CONSTRAINT "PK_NUMBER_STATUS" PRIMARY KEY
("STATUS_CODE");

This works fine in that LAST_UPDATE is updated each time a column in the row
in changed.

We have occasion to want to load data from, say, the production version of
this table to a table with the same definition in a test database.
Here's what I tried (coredv1 is the source database):

DECLARE load_curs CURSOR
DATABASE coredv1
FOR SELECT * FROM acctasgn.number_status;
LOAD FROM load_curs OF CURSOR
REPLACE INTO acctasgn.number_status;

Here are the results:
SQL3550W The field value in row "1" and column "3" is not NULL, but the
target column has been defined as GENERATED ALWAYS.

Obviously this is occuring because it's trying to insert the value of
LAST_UPDATE in the source table, and this is not allowed because it is
GENERATED ALWAYS.

Now, I can change the cursor to bypass this field, ie

DECLARE load_curs CURSOR
DATABASE coredv1
FOR SELECT STATUS_CODE, STATUS_DESCRIPTION
FROM acctasgn.number_status;
LOAD FROM load_curs OF CURSOR
REPLACE INTO acctasgn.number_status;

This works, but it makes LAST_UPDATE the timestamp of when I did the load,
and not the value as it is in the source table.
Technically this is 'not wrong' because that *is* in fact the date of the
last update in the destination table, but it's not really what I want.

I then tried using the load modifiers for generated columns, eg:

DECLARE load_curs CURSOR
DATABASE coredv1
FOR SELECT * FROM acctasgn.number_status;
LOAD FROM load_curs OF CURSOR
MODIFIED BY GENERATEDOVERRIDE
REPLACE INTO acctasgn.number_status;

This gives me the following error:
SQL3526N The modifier clause "GENERATEDOVERRIDE" is inconsistent with the
current load command. Reason code: "3".

Explanation:

The load file type mode (modifier) indicated, is incompatible with your
load/import/export command. This is because of one of the following
reasons:

3 Generated or identity related file type modifiers have been
specified but the target table contains no such columns.

I get the same basic thing for "generatedignore" and "generatedmissing".

Based on the documentation I have read
http://publib.boulder.ibm.com/infoce...?topic=/com.ib
m.db2.luw.admin.dm.doc/doc/c0004592.html
I would think that "generatedoverride" is what I am looking for, but perhaps
I am misreading it.

One thing that does work is if I replace "GENERATED ALWAYS FOR EACH ROW"
with "GENERATED BY DEFAULT FOR EACH ROW" in the DDL
..
The issue I have with this is, other than in this special situation, I don't
think we want to allow even the chance of having an application or a user
update this column directly. Am I just worried over nothing, and I should
go ahead and make this change (ALWAYS to BY DEFAULT)?

Thoughts?

Thanks,
Frank

Jun 27 '08 #1
1 11841
As so often occurs, I found the answer after posting the question...

DECLARE load_curs CURSOR
DATABASE jmtest
FOR SELECT * FROM customer.accounts;
LOAD FROM load_curs OF CURSOR
MODIFIED BY rowchangetimestampoverride
REPLACE INTO customer.accounts;

This seems to work fine.

One thing that concerns me with this, as with other modifiers such as
identityoverride and generatedoverride is that if there are no such columns
the entire statement is disallowed, rather than the option just being
ignored.

What I mean is that if a table does not have a ROW CHANGE TIMESTAMP column
and I try to load it using "MODIFIED BY rowchangetimestampoverride" it gives
me an error:

SQL3526N The modifier clause "ROWCHANGETIMESTAMPOVERRIDE" is inconsistent
with the current load command. Reason code: "3".

3 Generated or identity related file type modifiers have been
specified but the target table contains no such columns.

I want to be able to have a fairly generic process to load data in this
manner. With this type of 'error handling' in place it looks like I need to
first determine if the table has an IDENTITY column and a ROW CHANGE
TIMESTAMP column and any GENERATED columns before I can determine how to
build by LOAD statement.

Seems like rather a pain.
Plus I don't know how to do it programatically! I'm sure there are some
system tables I can query, but I'll need some help determining what they
are. My hope is that I will be able to write a stored procedure where the
user can call it just passing the name of the table and the source database
and/or source table. The SP will have to determine if any of the modifiers
are required. (That's the part I don't know how to do.)

Frank
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Astra | last post by:
Hi All I know an SQL Server timestamp seems to be as useful as rocking horse for show jumping, but I'm hoping you know a 'fudge' to get me round a problem or at least confirm that it isn't...
2
by: Mick White | last post by:
I inadvertantly named a field "in" mysql> select * from guestbook; +----+-------+-------+-----------------+----------------+ | id | fname | lname | comments | in |...
2
by: JS | last post by:
I have a del file with timestamp format as: Jan 1 1995 12:00AM I am trying to load this as: modified by timestampformat "MMM/D/YYYY HH:MM TT" but DB2 will not accept it. I have tried various...
5
by: John Richardson | last post by:
I've been bothered for some time about my DataGrid not populating my rows very quickly. I have about 10K rows loading into the grid. I create a datatable dt with 2 columns, an ID and a display. ...
2
by: Brendan Jurd | last post by:
Hello all, I have a particular application sitting on postgres that requires a complete log of all inserts, updates and deletes, along with the application user who made the change. There is a...
5
by: Prabu Subroto | last post by:
Dear my friends... I created some tables with field timestamp (datatype also timestamp). I mean, I want to have the data when each record inserted or modified in the tables. on MysQL, I just...
2
by: Russell Smith | last post by:
Timestamps support infinity. However if appears dates do not. When timestamps are cast to dates, there is no output. Is this an acceptable option or not? Below are a number of examples...
5
by: pankaj_wolfhunter | last post by:
Greetings, In Sybase, a timestamp column is automatically loaded by the DB engine and its in some hex format. This is shown below id timestamp_value ----------- ------------------ 1...
5
by: yeoj13 | last post by:
Hello, I have a db2load script I'm using to populate a large table. Ideally, my target table is required to have "Not Null" constraints on a number of different columns. I've noticed a ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.