Q:

Add values to table1 for each element from table2 and using MAX(id) + 1 from table1 as table2 id

I have table1 and table2 and want to do something like the following:
INSERT INTO table1 (ID, OWNER_ID, NAME) SELECT (SELECT MAX(ID) FROM table1) + 1, ID, 'value' FROM table2

The query above does not work and returns:
Unique index or primary key violation: "PRIMARY KEY ON PUBLIC.table1(ID)"; SQL statement:

Any help please?
table1:
| ID | OWNER_ID | NAME |
| --- | ---- | --- |

ŧable2:
| ID | OWNER_ID_REF | NAME |
| --- | ---- | --- |

Thanks

A:

set @i:=(SELECT MAX(ID) FROM table1);
INSERT INTO table1 (ID, OWNER_ID, NAME) SELECT @i:=@i+1, ID, 'value' FROM table2

try this query it will work fine

