3

The following works in Mysql 5.6.40, but not in 5.7.20:

create table test 
  select 1 as id, 'a' as data;

create or replace view v_test as 
  select t.* from test t
  left join test t1 using (id); -- doesn't have to be the same table, only used for simplicity

update v_test set data = 'b';

ERROR 1288 (HY000) at line 1: The target table v_test of the UPDATE is not updatable

The left join part seems to be what's triggering the error. However, the update is done on the left part of the join, so there shouldn't be any reason to disallow it. Moreover, the following works:

create or replace view v_test_ as 
  select t.* from test t
  join v_test using (id);

update v_test_
  set data = 'b';

This means that mysql can in fact process the query with a left join. Is there a good reason for refusing to update or was it some stickler for documentation who added an exception for left joins just because they are "outer"?

1
  • 1
    We are encountering this exact issue as well after upgrading to mysql 5.7, views with left joins that previously updated are no longer updatable. Changing to an inner join works (but of course gives different results entirely). Interestingly, using the same left join directly in the update statement (instead of using a view) works fine. The MySQL docs do say that outer joins are not permitted in updatable views, but this all worked fine previously and there is very little indication of this being a desired change. Dec 13, 2018 at 19:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.