DB2 Insert into a identity column

DB2 10.5 on Windows

I am trying to delete a lot of data from a table.  I created a duplicate of the table with a different name and am trying to move the last years worth of data to it, then truncate the original data and then move the saved data back to the original.

There is an ID column that is set up like this.

ID	INTEGER	NOT NULL	GENERATED ALWAYS
AS IDENTITY (START WITH 1, INCREMENT BY 1, CACHE 20,
NO MINVALUE, NO MAXVALUE, NO CYCLE, NO ORDER)

Open in new window


When I run this to move the data back

INSERT INTO ORIGINAL_TABLE OVERRIDING SYSTEM VALUE (SELECT * FROM DUPLICATE_TABLE WHERE  DATE(LASTTIME) >= '01-01-2017')

Open in new window


I get this

ERROR [42601] [IBM][DB2/NT64] SQL0104N  An unexpected token "OVERRIDING SYSTEM VALUE" was found following "ORIGINAL_TABLE".  Expected tokens may include:  "<space>".

Open in new window


Everything I have read says the OVERRIDING SYSTEM VALUE should work but it does not.  I am sure it is a simple issue but I have wasted 1/2 a day on trying to figure it out.  Any help would be greatly appreciated!!

Jim
Jim YoumansSr Database AdministratorAsked:
Who is Participating?
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi Jim,

The last I knew, the OVERRIDING SYSTEM/USER VALUE clause wasn't available in UDB.  I believe it originated in DB2 for iSeries and later made its way into mainframe DB2, but not to LUW.

If your database is offline while you make the changes, you can turn off the IDENTITY, insert the rows, and restart the IDENTITY.

ALTER TABLE xxx ALTER COLUMN id_column DROP IDENTITY;
--  Insert your rows here.
ALTER TABLE xxx ALTER COLUMN id_column set GENERATED ALWAYS AS IDENTITY (Start with yyy)
-- WHERE yyy is the highest value+1

Open in new window


Note that DB2 doesn't care that an identity column has multiple rows with the same value.  It doesn't check that integrity when an insert is done, it simply assigns the next value that the IDENTITY parameters indicate.  A unique index on the column, of course, does enforce uniqueness.


Kent
0
 
Jim YoumansSr Database AdministratorAuthor Commented:
Well that sucks.  Thank you for your help, I appreciate it!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.