[
https://issues.apache.org/jira/browse/CALCITE-6838?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
xiong duan updated CALCITE-6838:
--------------------------------
Description:
ReloSqlConverter should generate double parentheses when the input to Unnest is
a query statement.
For unit tests in RelToSqlConverterTest:
{code:java}
@Test void testUnnest() {
final String sql = "select * from UNNEST(array [1, 2, 3])";
final String expected = "SELECT *\n" +
"FROM UNNEST (SELECT ARRAY[1, 2, 3]\n" +
"FROM (VALUES (0)) AS \"t\" (\"ZERO\")) AS \"t0\" (\"col_0\")";
sql(sql).ok(expected).withPostgresql().ok(expected);
}{code}
The generated SQL is valid in CALCITE but not in PG.
In PostgreSQL:
{code:java}
CREATE TABLE IF NOT EXISTS public."unnestTable"
(
array_int integer[],
"valueInt" integer
);
SELECT "valueInt","t10"."col_0" FROM public."unnestTable",unnest(( SELECT
"array_int" FROM (VALUES (0)) AS "t" ("ZERO"))) AS "t10" ("col_0");
select * from unnest((SELECT "array_int" from public."unnestTable")) as "t"
("ZERO");
select * from unnest((SELECT ARRAY_AGG("valueInt") from public."unnestTable"))
as "t" ("ZERO");
select * from unnest((SELECT ARRAY_AGG("valueInt") from public."unnestTable"))
WITH ORDINALITY AS "t" ("ZERO","ZERO1");{code}
The PG always needs double parentheses.
The Calcite support double parentheses too.
was:
ReloSqlConverter should generate double parentheses when the input to Unnest is
a query statement.
For unit tests in RelToSqlConverterTest:
{code:java}
@Test void testUnnest() {
final String sql = "select * from UNNEST(array [1, 2, 3])";
final String expected = "SELECT *\n" +
"FROM UNNEST (SELECT ARRAY[1, 2, 3]\n" +
"FROM (VALUES (0)) AS \"t\" (\"ZERO\")) AS \"t0\" (\"col_0\")";
sql(sql).ok(expected).withPostgresql().ok(expected);
}{code}
The generated SQL is valid in CALCITE but not in PG.
In PostgreSQL:
{code:java}
CREATE TABLE IF NOT EXISTS public."unnestTable"
(
array_int integer[],
"valueInt" integer
);
SELECT "valueInt","t10"."col_0" FROM public."unnestTable",unnest(( SELECT
"array_int" FROM (VALUES (0)) AS "t" ("ZERO"))) AS "t10" ("col_0");
select * from unnest((SELECT "array_int" from public."unnestTable")) as "t"
("ZERO");
select * from unnest((SELECT ARRAY_AGG("valueInt") from public."unnestTable"))
as "t" ("ZERO");
select * from unnest((SELECT ARRAY_AGG("valueInt") from public."unnestTable"))
WITH ORDINALITY AS "t" ("ZERO","ZERO1");{code}
PG always need double parentheses.
> ReloSqlConverter should generate double parentheses when the input to Unnest
> is a query statement
> -------------------------------------------------------------------------------------------------
>
> Key: CALCITE-6838
> URL: https://issues.apache.org/jira/browse/CALCITE-6838
> Project: Calcite
> Issue Type: Bug
> Reporter: xiong duan
> Priority: Major
>
> ReloSqlConverter should generate double parentheses when the input to Unnest
> is a query statement.
> For unit tests in RelToSqlConverterTest:
> {code:java}
> @Test void testUnnest() {
> final String sql = "select * from UNNEST(array [1, 2, 3])";
> final String expected = "SELECT *\n" +
> "FROM UNNEST (SELECT ARRAY[1, 2, 3]\n" +
> "FROM (VALUES (0)) AS \"t\" (\"ZERO\")) AS \"t0\" (\"col_0\")";
> sql(sql).ok(expected).withPostgresql().ok(expected);
> }{code}
> The generated SQL is valid in CALCITE but not in PG.
> In PostgreSQL:
> {code:java}
> CREATE TABLE IF NOT EXISTS public."unnestTable"
> (
> array_int integer[],
> "valueInt" integer
> );
> SELECT "valueInt","t10"."col_0" FROM public."unnestTable",unnest(( SELECT
> "array_int" FROM (VALUES (0)) AS "t" ("ZERO"))) AS "t10" ("col_0");
> select * from unnest((SELECT "array_int" from public."unnestTable")) as "t"
> ("ZERO");
> select * from unnest((SELECT ARRAY_AGG("valueInt") from
> public."unnestTable")) as "t" ("ZERO");
> select * from unnest((SELECT ARRAY_AGG("valueInt") from
> public."unnestTable")) WITH ORDINALITY AS "t" ("ZERO","ZERO1");{code}
> The PG always needs double parentheses.
> The Calcite support double parentheses too.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)