Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn on/off IDENTITY_INSERT in Redshift

I have to turn off the identity on a table in redshift and insert the historical values into that.

If I try to insert values into an identity column I am getting below error

ERROR: 0A000: cannot set an identity column to a value

like image 647
ks_rajesh Avatar asked Sep 12 '15 17:09

ks_rajesh


People also ask

What is when Identity_insert is set to off?

IDENTITY_INSERT off in SQL Server Once you have turned the IDENTITY_INSERT option OFF, you cannot insert explicit values in the identity column of the table. Also, the value will be set automatically by increment in the identity column if you try to insert a new record.

What is Identity_insert is set to ON?

If the value inserted is larger than the current identity value for the table, SQL Server automatically uses the new inserted value as the current identity value. The setting of SET IDENTITY_INSERT is set at execute or run time and not at parse time.


1 Answers

you can do it by following simple 2 step approach.

  1. unload the historical table data and put it into file @s3
  2. run copy command against this file to load target table by specifying explicit_ids as parameter in your copy command.
like image 62
Raks Avatar answered Oct 06 '22 01:10

Raks