diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-08-10 09:23:46 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-08-10 09:23:46 +0000 |
commit | 5dde903f4f6659e384287a3e508b9f369c5a2ba3 (patch) | |
tree | 05cd2920d82f0023f6ac695dbb6eaeef64608401 /tests/fixtures/optimizer/qualify_columns.sql | |
parent | Adding upstream version 17.9.1. (diff) | |
download | sqlglot-5dde903f4f6659e384287a3e508b9f369c5a2ba3.tar.xz sqlglot-5dde903f4f6659e384287a3e508b9f369c5a2ba3.zip |
Adding upstream version 17.11.0.upstream/17.11.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | tests/fixtures/optimizer/qualify_columns.sql | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/tests/fixtures/optimizer/qualify_columns.sql b/tests/fixtures/optimizer/qualify_columns.sql index 8a2519e..7ba8e54 100644 --- a/tests/fixtures/optimizer/qualify_columns.sql +++ b/tests/fixtures/optimizer/qualify_columns.sql @@ -125,7 +125,7 @@ SELECT COALESCE(x.a) AS d FROM x JOIN y ON x.b = y.b GROUP BY d; SELECT COALESCE(x.a) AS d FROM x AS x JOIN y AS y ON x.b = y.b GROUP BY COALESCE(x.a); SELECT a + 1 AS d FROM x WHERE d > 1; -SELECT x.a + 1 AS d FROM x AS x WHERE x.a + 1 > 1; +SELECT x.a + 1 AS d FROM x AS x WHERE (x.a + 1) > 1; # execute: false SELECT a + 1 AS d, d + 2 FROM x; @@ -300,6 +300,12 @@ WITH z AS (SELECT x.a AS a, x.b AS b FROM x AS x), q AS (SELECT z.b AS b FROM z) WITH z AS ((SELECT b FROM x UNION ALL SELECT b FROM y) ORDER BY b) SELECT * FROM z; WITH z AS ((SELECT x.b AS b FROM x AS x UNION ALL SELECT y.b AS b FROM y AS y) ORDER BY b) SELECT z.b AS b FROM z; +WITH cte(x) AS (SELECT 1) SELECT * FROM cte AS cte(a); +WITH cte AS (SELECT 1 AS x) SELECT cte.a AS a FROM cte AS cte(a); + +WITH cte(x, y) AS (SELECT 1, 2) SELECT cte.* FROM cte AS cte(a); +WITH cte AS (SELECT 1 AS x, 2 AS y) SELECT cte.a AS a, cte.y AS y FROM cte AS cte(a); + -------------------------------------- -- Except and Replace -------------------------------------- @@ -383,6 +389,9 @@ SELECT x.b AS b FROM t AS t JOIN x AS x ON t.a = x.a; SELECT a FROM t1 JOIN t2 USING(a); SELECT COALESCE(t1.a, t2.a) AS a FROM t1 AS t1 JOIN t2 AS t2 ON t1.a = t2.a; +WITH m(a) AS (SELECT 1), n(b) AS (SELECT 1) SELECT * FROM m JOIN n AS foo(a) USING (a); +WITH m AS (SELECT 1 AS a), n AS (SELECT 1 AS b) SELECT COALESCE(m.a, foo.a) AS a FROM m JOIN n AS foo(a) ON m.a = foo.a; + -------------------------------------- -- Hint with table reference -------------------------------------- @@ -444,7 +453,7 @@ SELECT x.a AS a, x.b AS b FROM x AS x QUALIFY COUNT(x.a) OVER (PARTITION BY x.b) -- Expand laterals -------------------------------------- # execute: false -select 2 AS d, d + 1 FROM x WHERE d = 2 GROUP BY d; +SELECT 2 AS d, d + 1 FROM x WHERE d = 2 GROUP BY d; SELECT 2 AS d, 2 + 1 AS _col_1 FROM x AS x WHERE 2 = 2 GROUP BY 1; # title: expand alias reference @@ -471,6 +480,16 @@ FROM ( ); SELECT _q_0.i AS i, _q_0.j AS j FROM (SELECT x.a + 1 AS i, x.a + 1 + 1 AS j FROM x AS x) AS _q_0; +# title: wrap expanded alias to ensure operator precedence isn't broken +# execute: false +SELECT x.a + x.b AS f, f * x.b FROM x; +SELECT x.a + x.b AS f, (x.a + x.b) * x.b AS _col_1 FROM x AS x; + +# title: no need to wrap expanded alias +# execute: false +SELECT x.a + x.b AS f, f, f + 5 FROM x; +SELECT x.a + x.b AS f, x.a + x.b AS _col_1, x.a + x.b + 5 AS _col_2 FROM x AS x; + -------------------------------------- -- Wrapped tables / join constructs -------------------------------------- |