1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

check of using same table for changing and select

This commit is contained in:
bell@sanja.is.com.ua
2002-11-30 19:26:18 +02:00
parent fd11c80400
commit 9da705ef2f
8 changed files with 96 additions and 20 deletions

View File

@ -411,6 +411,8 @@ a b
0 10
1 11
2 12
update t1 set b= (select b from t1);
INSERT TABLE 't1' isn't allowed in FROM table list
update t1 set b= (select b from t2 where t1.a = t2.a);
select * from t1;
a b
@ -430,6 +432,8 @@ a b
select * from t1 where b = (select b from t2 where t1.a = t2.a);
a b
2 12
delete from t1 where b = (select b from t1);
INSERT TABLE 't1' isn't allowed in FROM table list
delete from t1 where b = (select b from t2 where t1.a = t2.a);
select * from t1;
a b
@ -453,6 +457,8 @@ a b
33 10
22 11
2 12
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t12 where t11.a = t12.a);
INSERT TABLE 't12' isn't allowed in FROM table list
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2 where t11.a = t2.a);
select * from t11;
a b
@ -466,6 +472,8 @@ drop table t11, t12, t2;
CREATE TABLE t1 (x int);
create table t2 (a int);
insert into t2 values (1);
INSERT INTO t1 (x) VALUES ((SELECT x FROM t1));
INSERT TABLE 't1' isn't allowed in FROM table list
INSERT INTO t1 (x) VALUES ((SELECT a FROM t2));
select * from t1;
x
@ -485,20 +493,22 @@ x
3
INSERT INTO t1 (x) select (SELECT SUM(x)+2 FROM t1) FROM t2;
INSERT TABLE 't1' isn't allowed in FROM table list
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(x) FROM t1));
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(x) FROM t2));
select * from t1;
x
1
2
3
3
9
0
drop table t1, t2;
CREATE TABLE t1 (x int not null, y int, primary key (x));
create table t2 (a int);
insert into t2 values (1);
select * from t1;
x y
replace into t1 (x, y) VALUES ((SELECT x FROM t1), (SELECT a+1 FROM t2));
INSERT TABLE 't1' isn't allowed in FROM table list
replace into t1 (x, y) VALUES ((SELECT a FROM t2), (SELECT a+1 FROM t2));
select * from t1;
x y
@ -559,4 +569,10 @@ id
SELECT * FROM t WHERE id IN (SELECT 5 UNION SELECT 2);
id
2
drop table if exists t;
INSERT INTO t VALUES ((SELECT * FROM t));
INSERT TABLE 't' isn't allowed in FROM table list
SELECT * FROM t;
id
1
2
drop table t;

View File

@ -245,6 +245,8 @@ create table t2 (a int NOT NULL, b int, primary key (a));
insert into t1 values (0, 10),(1, 11),(2, 12);
insert into t2 values (1, 21),(2, 22),(3, 23);
select * from t1;
-- error 1093
update t1 set b= (select b from t1);
update t1 set b= (select b from t2 where t1.a = t2.a);
select * from t1;
drop table t1, t2;
@ -256,6 +258,8 @@ insert into t1 values (0, 10),(1, 11),(2, 12);
insert into t2 values (1, 21),(2, 12),(3, 23);
select * from t1;
select * from t1 where b = (select b from t2 where t1.a = t2.a);
-- error 1093
delete from t1 where b = (select b from t1);
delete from t1 where b = (select b from t2 where t1.a = t2.a);
select * from t1;
drop table t1, t2;
@ -270,6 +274,8 @@ insert into t12 values (33, 10),(22, 11),(2, 12);
insert into t2 values (1, 21),(2, 12),(3, 23);
select * from t11;
select * from t12;
-- error 1093
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t12 where t11.a = t12.a);
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2 where t11.a = t2.a);
select * from t11;
select * from t12;
@ -279,6 +285,8 @@ drop table t11, t12, t2;
CREATE TABLE t1 (x int);
create table t2 (a int);
insert into t2 values (1);
-- error 1093
INSERT INTO t1 (x) VALUES ((SELECT x FROM t1));
INSERT INTO t1 (x) VALUES ((SELECT a FROM t2));
select * from t1;
insert into t2 values (1);
@ -289,7 +297,7 @@ INSERT INTO t1 (x) select (SELECT SUM(a)+1 FROM t2) FROM t2;
select * from t1;
-- error 1093
INSERT INTO t1 (x) select (SELECT SUM(x)+2 FROM t1) FROM t2;
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(x) FROM t1));
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(x) FROM t2));
-- sleep 1
select * from t1;
drop table t1, t2;
@ -299,6 +307,8 @@ CREATE TABLE t1 (x int not null, y int, primary key (x));
create table t2 (a int);
insert into t2 values (1);
select * from t1;
-- error 1093
replace into t1 (x, y) VALUES ((SELECT x FROM t1), (SELECT a+1 FROM t2));
replace into t1 (x, y) VALUES ((SELECT a FROM t2), (SELECT a+1 FROM t2));
select * from t1;
replace into t1 (x, y) VALUES ((SELECT a FROM t2), (SELECT a+2 FROM t2));
@ -326,5 +336,7 @@ EXPLAIN SELECT * FROM t WHERE id IN (SELECT 1+(select 1));
EXPLAIN SELECT * FROM t WHERE id IN (SELECT 1 UNION SELECT 3);
SELECT * FROM t WHERE id IN (SELECT 5 UNION SELECT 3);
SELECT * FROM t WHERE id IN (SELECT 5 UNION SELECT 2);
drop table if exists t;
-- error 1093
INSERT INTO t VALUES ((SELECT * FROM t));
SELECT * FROM t;
drop table t;