Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redshift - inserting into identity column

I have created a table as mentioned below.

create table employee (
surrogate_key bigint IDENTITY(1,1), 
first_name varchar(200), 
last_name varchar(200), 
phone_number varchar(200), 
creditcard_number bigint
)

insert into employee values 
('gaurang', 'shah', '356-776-4456', '4716973408090483')

However, following code is giving error.

Error

[Code: 500310, SQL State: 0A000]  [Amazon](500310) Invalid operation: cannot set an identity column to a value;
like image 319
Gaurang Shah Avatar asked Jun 12 '26 23:06

Gaurang Shah


1 Answers

One more option is define surrogate key with default like this

surrogate_key bigint generated by default as IDENTITY(1,1),

Then run this query

insert into employee1

values(default,'gaurang', 'shah', '356-776-4456', 4716973408090483)

like image 68
Amish Shah Avatar answered Jun 17 '26 11:06

Amish Shah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!