MySQL update subselect issue -
before post question, tell all, not duplicate of this or that, since not want solve specific issue, rather desire understand one. reading docs, can see 2 interesting examples of anomalies regarding subqueries inside update
command:
update t1 set column2 = (select max(column1) t1);
the error is
error 1093 (er_update_table_used) sqlstate = hy000 message = "you can't specify target table 'x' update in clause"
2.
select * t1 s1 in (select s2 t2 order s1 limit 1)
the error is
error 1235 (er_not_supported_yet) sqlstate = 42000 message = "this version of mysql doesn't yet support 'limit & in/all/any/some subquery'"
looking @ first example can tell updating column2
of t1
might or might not change column1
values, instance because of triggers or if columns same. however, wonder why mysql throwing error instead of evaluating subquery normally, or @ least, determining whether possible subquery's result changed update
while command running? second example, not understand why mysql not support syntax. consider these mysql bugs , wonder whether there schedule when fixed.
mysql functionally limited dbms compared other dbms. these limitations mentioned not being removed oracle (the owner of mysql) due several reasons. limitations mention documented mysql. there ways around these issues observe:
example replacement 1:
create temporary table ttt select max(column1) col1 t1; update t1 set column2 = (select col1 ttt);
example replacement 2:
create view ttt2 select s2 t2 order s1 limit 1; select * t1 s1 in (select s2 ttt2);
(strangely enough works while syntactically same...).
optional: start using mariadb (100% backward compatible mysql), , contribute in project. fixing long standing functionality issues.
Comments
Post a Comment