⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 join.out

📁 PostgreSQL7.4.6 for Linux
💻 OUT
📖 第 1 页 / 共 5 页
字号:
  ORDER BY i; xxx | i | j |   t   | k  -----+---+---+-------+----     | 0 |   | zero  |        | 1 | 4 | one   | -1     | 2 | 3 | two   |  2     | 2 | 3 | two   |  4     | 3 | 2 | three | -3     | 4 | 1 | four  |        | 5 | 0 | five  | -5     | 5 | 0 | five  | -5     | 6 | 6 | six   |        | 7 | 7 | seven |        | 8 | 8 | eight |        |   |   | null  |        |   | 0 | zero  |   (13 rows)SELECT '' AS "xxx", *  FROM J1_TBL LEFT JOIN J2_TBL USING (i)  ORDER BY i; xxx | i | j |   t   | k  -----+---+---+-------+----     | 0 |   | zero  |        | 1 | 4 | one   | -1     | 2 | 3 | two   |  2     | 2 | 3 | two   |  4     | 3 | 2 | three | -3     | 4 | 1 | four  |        | 5 | 0 | five  | -5     | 5 | 0 | five  | -5     | 6 | 6 | six   |        | 7 | 7 | seven |        | 8 | 8 | eight |        |   |   | null  |        |   | 0 | zero  |   (13 rows)SELECT '' AS "xxx", *  FROM J1_TBL RIGHT OUTER JOIN J2_TBL USING (i); xxx | i | j |   t   | k  -----+---+---+-------+----     | 0 |   | zero  |        | 1 | 4 | one   | -1     | 2 | 3 | two   |  2     | 2 | 3 | two   |  4     | 3 | 2 | three | -3     | 5 | 0 | five  | -5     | 5 | 0 | five  | -5     |   |   |       |        |   |   |       |  0(9 rows)SELECT '' AS "xxx", *  FROM J1_TBL RIGHT JOIN J2_TBL USING (i); xxx | i | j |   t   | k  -----+---+---+-------+----     | 0 |   | zero  |        | 1 | 4 | one   | -1     | 2 | 3 | two   |  2     | 2 | 3 | two   |  4     | 3 | 2 | three | -3     | 5 | 0 | five  | -5     | 5 | 0 | five  | -5     |   |   |       |        |   |   |       |  0(9 rows)SELECT '' AS "xxx", *  FROM J1_TBL FULL OUTER JOIN J2_TBL USING (i)  ORDER BY i, t; xxx | i | j |   t   | k  -----+---+---+-------+----     | 0 |   | zero  |        | 1 | 4 | one   | -1     | 2 | 3 | two   |  2     | 2 | 3 | two   |  4     | 3 | 2 | three | -3     | 4 | 1 | four  |        | 5 | 0 | five  | -5     | 5 | 0 | five  | -5     | 6 | 6 | six   |        | 7 | 7 | seven |        | 8 | 8 | eight |        |   |   | null  |        |   | 0 | zero  |        |   |   |       |        |   |   |       |  0(15 rows)SELECT '' AS "xxx", *  FROM J1_TBL FULL JOIN J2_TBL USING (i)  ORDER BY i, t; xxx | i | j |   t   | k  -----+---+---+-------+----     | 0 |   | zero  |        | 1 | 4 | one   | -1     | 2 | 3 | two   |  2     | 2 | 3 | two   |  4     | 3 | 2 | three | -3     | 4 | 1 | four  |        | 5 | 0 | five  | -5     | 5 | 0 | five  | -5     | 6 | 6 | six   |        | 7 | 7 | seven |        | 8 | 8 | eight |        |   |   | null  |        |   | 0 | zero  |        |   |   |       |        |   |   |       |  0(15 rows)SELECT '' AS "xxx", *  FROM J1_TBL LEFT JOIN J2_TBL USING (i) WHERE (k = 1); xxx | i | j | t | k -----+---+---+---+---(0 rows)SELECT '' AS "xxx", *  FROM J1_TBL LEFT JOIN J2_TBL USING (i) WHERE (i = 1); xxx | i | j |  t  | k  -----+---+---+-----+----     | 1 | 4 | one | -1(1 row)---- More complicated constructs---- UNION JOIN isn't implemented yetSELECT '' AS "xxx", *  FROM J1_TBL UNION JOIN J2_TBL;ERROR:  UNION JOIN is not implemented---- Multiway full join--CREATE TABLE t1 (name TEXT, n INTEGER);CREATE TABLE t2 (name TEXT, n INTEGER);CREATE TABLE t3 (name TEXT, n INTEGER);INSERT INTO t1 VALUES ( 'aa', 11 );INSERT INTO t2 VALUES ( 'aa', 12 );INSERT INTO t2 VALUES ( 'bb', 22 );INSERT INTO t2 VALUES ( 'dd', 42 );INSERT INTO t3 VALUES ( 'aa', 13 );INSERT INTO t3 VALUES ( 'bb', 23 );INSERT INTO t3 VALUES ( 'cc', 33 );SELECT * FROM t1 FULL JOIN t2 USING (name) FULL JOIN t3 USING (name); name | n  | n  | n  ------+----+----+---- aa   | 11 | 12 | 13 bb   |    | 22 | 23 cc   |    |    | 33 dd   |    | 42 |   (4 rows)---- Test interactions of join syntax and subqueries---- Basic cases (we expect planner to pull up the subquery here)SELECT * FROM(SELECT * FROM t2) as s2INNER JOIN(SELECT * FROM t3) s3USING (name); name | n  | n  ------+----+---- aa   | 12 | 13 bb   | 22 | 23(2 rows)SELECT * FROM(SELECT * FROM t2) as s2LEFT JOIN(SELECT * FROM t3) s3USING (name); name | n  | n  ------+----+---- aa   | 12 | 13 bb   | 22 | 23 dd   | 42 |   (3 rows)SELECT * FROM(SELECT * FROM t2) as s2FULL JOIN(SELECT * FROM t3) s3USING (name); name | n  | n  ------+----+---- aa   | 12 | 13 bb   | 22 | 23 cc   |    | 33 dd   | 42 |   (4 rows)-- Cases with non-nullable expressions in subquery results;-- make sure these go to null as expectedSELECT * FROM(SELECT name, n as s2_n, 2 as s2_2 FROM t2) as s2NATURAL INNER JOIN(SELECT name, n as s3_n, 3 as s3_2 FROM t3) s3; name | s2_n | s2_2 | s3_n | s3_2 ------+------+------+------+------ aa   |   12 |    2 |   13 |    3 bb   |   22 |    2 |   23 |    3(2 rows)SELECT * FROM(SELECT name, n as s2_n, 2 as s2_2 FROM t2) as s2NATURAL LEFT JOIN(SELECT name, n as s3_n, 3 as s3_2 FROM t3) s3; name | s2_n | s2_2 | s3_n | s3_2 ------+------+------+------+------ aa   |   12 |    2 |   13 |    3 bb   |   22 |    2 |   23 |    3 dd   |   42 |    2 |      |     (3 rows)SELECT * FROM(SELECT name, n as s2_n, 2 as s2_2 FROM t2) as s2NATURAL FULL JOIN(SELECT name, n as s3_n, 3 as s3_2 FROM t3) s3; name | s2_n | s2_2 | s3_n | s3_2 ------+------+------+------+------ aa   |   12 |    2 |   13 |    3 bb   |   22 |    2 |   23 |    3 cc   |      |      |   33 |    3 dd   |   42 |    2 |      |     (4 rows)SELECT * FROM(SELECT name, n as s1_n, 1 as s1_1 FROM t1) as s1NATURAL INNER JOIN(SELECT name, n as s2_n, 2 as s2_2 FROM t2) as s2NATURAL INNER JOIN(SELECT name, n as s3_n, 3 as s3_2 FROM t3) s3; name | s1_n | s1_1 | s2_n | s2_2 | s3_n | s3_2 ------+------+------+------+------+------+------ aa   |   11 |    1 |   12 |    2 |   13 |    3(1 row)SELECT * FROM(SELECT name, n as s1_n, 1 as s1_1 FROM t1) as s1NATURAL FULL JOIN(SELECT name, n as s2_n, 2 as s2_2 FROM t2) as s2NATURAL FULL JOIN(SELECT name, n as s3_n, 3 as s3_2 FROM t3) s3; name | s1_n | s1_1 | s2_n | s2_2 | s3_n | s3_2 ------+------+------+------+------+------+------ aa   |   11 |    1 |   12 |    2 |   13 |    3 bb   |      |      |   22 |    2 |   23 |    3 cc   |      |      |      |      |   33 |    3 dd   |      |      |   42 |    2 |      |     (4 rows)SELECT * FROM(SELECT name, n as s1_n FROM t1) as s1NATURAL FULL JOIN  (SELECT * FROM    (SELECT name, n as s2_n FROM t2) as s2    NATURAL FULL JOIN    (SELECT name, n as s3_n FROM t3) as s3  ) ss2; name | s1_n | s2_n | s3_n ------+------+------+------ aa   |   11 |   12 |   13 bb   |      |   22 |   23 cc   |      |      |   33 dd   |      |   42 |     (4 rows)SELECT * FROM(SELECT name, n as s1_n FROM t1) as s1NATURAL FULL JOIN  (SELECT * FROM    (SELECT name, n as s2_n, 2 as s2_2 FROM t2) as s2    NATURAL FULL JOIN    (SELECT name, n as s3_n FROM t3) as s3  ) ss2; name | s1_n | s2_n | s2_2 | s3_n ------+------+------+------+------ aa   |   11 |   12 |    2 |   13 bb   |      |   22 |    2 |   23 cc   |      |      |      |   33 dd   |      |   42 |    2 |     (4 rows)-- Test for propagation of nullability constraints into sub-joinscreate temp table x (x1 int, x2 int);insert into x values (1,11);insert into x values (2,22);insert into x values (3,null);insert into x values (4,44);insert into x values (5,null);create temp table y (y1 int, y2 int);insert into y values (1,111);insert into y values (2,222);insert into y values (3,333);insert into y values (4,null);select * from x; x1 | x2 ----+----  1 | 11  2 | 22  3 |     4 | 44  5 |   (5 rows)select * from y; y1 | y2  ----+-----  1 | 111  2 | 222  3 | 333  4 |    (4 rows)select * from x left join y on (x1 = y1 and x2 is not null); x1 | x2 | y1 | y2  ----+----+----+-----  1 | 11 |  1 | 111  2 | 22 |  2 | 222  3 |    |    |      4 | 44 |  4 |      5 |    |    |    (5 rows)select * from x left join y on (x1 = y1 and y2 is not null); x1 | x2 | y1 | y2  ----+----+----+-----  1 | 11 |  1 | 111  2 | 22 |  2 | 222  3 |    |  3 | 333  4 | 44 |    |      5 |    |    |    (5 rows)select * from (x left join y on (x1 = y1)) left join x xx(xx1,xx2)on (x1 = xx1); x1 | x2 | y1 | y2  | xx1 | xx2 ----+----+----+-----+-----+-----  1 | 11 |  1 | 111 |   1 |  11  2 | 22 |  2 | 222 |   2 |  22  3 |    |  3 | 333 |   3 |      4 | 44 |  4 |     |   4 |  44  5 |    |    |     |   5 |    (5 rows)select * from (x left join y on (x1 = y1)) left join x xx(xx1,xx2)on (x1 = xx1 and x2 is not null); x1 | x2 | y1 | y2  | xx1 | xx2 ----+----+----+-----+-----+-----  1 | 11 |  1 | 111 |   1 |  11  2 | 22 |  2 | 222 |   2 |  22  3 |    |  3 | 333 |     |      4 | 44 |  4 |     |   4 |  44  5 |    |    |     |     |    (5 rows)select * from (x left join y on (x1 = y1)) left join x xx(xx1,xx2)on (x1 = xx1 and y2 is not null); x1 | x2 | y1 | y2  | xx1 | xx2 ----+----+----+-----+-----+-----  1 | 11 |  1 | 111 |   1 |  11  2 | 22 |  2 | 222 |   2 |  22  3 |    |  3 | 333 |   3 |      4 | 44 |  4 |     |     |      5 |    |    |     |     |    (5 rows)select * from (x left join y on (x1 = y1)) left join x xx(xx1,xx2)on (x1 = xx1 and xx2 is not null); x1 | x2 | y1 | y2  | xx1 | xx2 ----+----+----+-----+-----+-----  1 | 11 |  1 | 111 |   1 |  11  2 | 22 |  2 | 222 |   2 |  22  3 |    |  3 | 333 |     |      4 | 44 |  4 |     |   4 |  44  5 |    |    |     |     |    (5 rows)-- these should NOT give the same answers as aboveselect * from (x left join y on (x1 = y1)) left join x xx(xx1,xx2)on (x1 = xx1) where (x2 is not null); x1 | x2 | y1 | y2  | xx1 | xx2 ----+----+----+-----+-----+-----  1 | 11 |  1 | 111 |   1 |  11  2 | 22 |  2 | 222 |   2 |  22  4 | 44 |  4 |     |   4 |  44(3 rows)select * from (x left join y on (x1 = y1)) left join x xx(xx1,xx2)on (x1 = xx1) where (y2 is not null); x1 | x2 | y1 | y2  | xx1 | xx2 ----+----+----+-----+-----+-----  1 | 11 |  1 | 111 |   1 |  11  2 | 22 |  2 | 222 |   2 |  22  3 |    |  3 | 333 |   3 |    (3 rows)select * from (x left join y on (x1 = y1)) left join x xx(xx1,xx2)on (x1 = xx1) where (xx2 is not null); x1 | x2 | y1 | y2  | xx1 | xx2 ----+----+----+-----+-----+-----  1 | 11 |  1 | 111 |   1 |  11  2 | 22 |  2 | 222 |   2 |  22  4 | 44 |  4 |     |   4 |  44(3 rows)---- regression test: check for bug with propagation of implied equality-- to outside an IN--select count(*) from tenk1 a where unique1 in  (select unique1 from tenk1 b join tenk1 c using (unique1)   where b.unique2 = 42); count -------     1(1 row)---- Clean up--DROP TABLE t1;DROP TABLE t2;DROP TABLE

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -