mysql - INSERT INTO ... SELECT if destination column has a generated column -


have tables:

create table `asource` (   `id` int(10) unsigned not null default '0' );  create table `adestination` (   `id` int(10) unsigned not null default '0',   `generated` tinyint(1) generated (id = 2) stored not null ); 

i copy row asource adestination:

insert adestination  select asource.*  asource; 

the above generates error:

error code: 1136. column count doesn't match value count @ row 1 

ok, quite strange require me mention generated query. ok, add column query:

insert adestination  select asource.*, null `generated` asource; 

this has worked fine in 5.7.10. however, generates error in 5.7.11 (due fix:

error code: 3105. value specified generated column 'generated' in table 'adestination' not allowed. 

ok, next try:

insert adestination  select asource.*, 1 `generated` asource; 

but still same error. have tried 0, true, false error persists.

the default value stated allowed value (specs or docs). however, following generates syntax error (default not supported there):

insert adestination  select asource.*, default `generated` asource; 

so, how can copy row 1 table using insert ... select if destination table adds columns of them generated?

the code calling query generic , has no knowledge columns particular tables have. knows columns destination table has. source table live table, destination table historical version of source table. has few columns user id made change, type of change (insert, update, delete) when etc.

you must declare columns

insert adestination (id, generated)  select id, 1  asource;  

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -