CREATE TABLE LIKE doesn't preserve IDENTITY
I tried the following: drop table if exists public.test; drop table if exists public.copytest; create table public.test(id IDENTITY(1,1), name varchar(80)); insert into public.test(name) VALUES ('bla'); create table public.copytest like public.test; insert into public.copytest(name) VALUES ('bla'); I get an error at the last statement because it needs the id column. Somehow, IDENTITY is not copied. Is there a way around this?
0
Comments
You can workaround the issue by creating a sequence
Using your example above.
drop table if exists public.test;
drop table if exists public.copytest;
create table public.test(id IDENTITY(1,1), name varchar(80));
insert into public.test(name) VALUES ('bla');
create table public.copytest like public.test;
create sequence s minvalue 1 maxvalue 100 increment 1 cache 1;
alter taBLE copytest alter column id set default s.nextval;
insert into public.copytest(name) values('bla');
select * from copytest;
select * from test;
Perhaps attach to the same JIRA in the database ?