Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert with ascending CURRENT TIMESTAMP 1

Status
Not open for further replies.

Darkwing99

Programmer
May 21, 2003
21
DE
Hi experts,

I have to fill rows into a database with an insert-statement.
The problem is the primary (unique) key. The column is named TS_INSERT and it should be the TS, when the row was inserted.

But when I write:
Code:
INSERT INTO table1
SELECT CURRENT TIMESTAMP
     , var2
     , var3
     , var4
FROM   table2
WHERE
       ....

DB2 stops with SQL -803 because all "CURRENT TIMESTAMP" are the same.

Is there a workaround for this problem?

Regards,
Thomas
 
I think that, to get unique timestamps you may have to insert the rows one at a time, possibly in a looping SQL procedure. Even then I am not sure if the timestamp will be updated for each iteration.
 
Try this one:
db2 "insert into t1 select cast(generate_unique() as timestamp), c2 from t3"

That works for me on a workstation UDB, background is that generate_unique() is also 'just' a timstamp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top