[ https://issues.apache.org/jira/browse/CALCITE-5711?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
xiong duan updated CALCITE-5711: -------------------------------- Description: When we use the SQL including the scalar query, converting this SQL Rel to PostgreSQL will include the SINGLE_VALUE aggregation function(PostgreSQL can't handle it) in the dialect SQL. Input SQL: {code:java} select "product_class_id" as c from "product" where "brand_name" = (select "product_name" from "product") {code} PostgreSQL Dialect now generates SQL: {code:java} SELECT \"product\".\"product_class_id\" AS \"C\" FROM \"foodmart\".\"product\" LEFT JOIN (SELECT SINGLE_VALUE(\"product_name\") AS \"$f0\" FROM \"foodmart\".\"product\") AS \"t0\" ON TRUE WHERE \"product\".\"brand_name\" = \"t0\".\"$f0\" {code} PostgreSQL Dialect will generate SQL: {code:java} SELECT "product"."product_class_id" AS "C" FROM "foodmart"."product" LEFT JOIN (SELECT CASE COUNT( {code} {color:#009100}*{color} {code:java} ) WHEN 0 THEN NULL WHEN 1 THEN MIN("product_name") ELSE (SELECT CAST(NULL AS VARCHAR(60)) UNION ALL SELECT CAST(NULL AS VARCHAR(60))) END AS "$f0" FROM "foodmart"."product") AS "t0" ON TRUE WHERE "product"."brand_name" = "t0"."$f0" {code} was: When we use the SQL including the scalar query, converting this SQL Rel to PostgreSQL will include the SINGLE_VALUE aggregation function(PostgreSQL can't handle it) in the dialect SQL. Input SQL: {code:java} select "product_class_id" as c from "product" where "brand_name" = (select "product_name" from "product") {code} PostgreSQL Dialect now generates SQL: {code:java} SELECT \"product\".\"product_class_id\" AS \"C\" FROM \"foodmart\".\"product\" LEFT JOIN (SELECT SINGLE_VALUE(\"product_name\") AS \"$f0\" FROM \"foodmart\".\"product\") AS \"t0\" ON TRUE WHERE \"product\".\"brand_name\" = \"t0\".\"$f0\" {code} PostgreSQL Dialect will generate SQL: {code:java} SELECT "product"."product_class_id" AS "C" FROM "foodmart"."product" LEFT JOIN (SELECT CASE COUNT("product_name") WHEN 0 THEN NULL WHEN 1 THEN MIN("product_name") ELSE (SELECT CAST(NULL AS VARCHAR(60)) UNION ALL SELECT CAST(NULL AS VARCHAR(60))) END AS "$f0" FROM "foodmart"."product") AS "t0" ON TRUE WHERE "product"."brand_name" = "t0"."$f0" {code} > Implement the SINGLE_VALUE aggregation in PostgreSQL Dialect > ------------------------------------------------------------ > > Key: CALCITE-5711 > URL: https://issues.apache.org/jira/browse/CALCITE-5711 > Project: Calcite > Issue Type: Bug > Components: core > Affects Versions: 1.34.0 > Reporter: xiong duan > Assignee: xiong duan > Priority: Major > Fix For: 1.35.0 > > > When we use the SQL including the scalar query, converting this SQL Rel to > PostgreSQL will include the SINGLE_VALUE aggregation function(PostgreSQL > can't handle it) in the dialect SQL. > Input SQL: > {code:java} > select "product_class_id" as c > from "product" where "brand_name" = (select "product_name" from "product") > {code} > PostgreSQL Dialect now generates SQL: > {code:java} > SELECT \"product\".\"product_class_id\" AS \"C\" > FROM \"foodmart\".\"product\" > LEFT JOIN (SELECT SINGLE_VALUE(\"product_name\") AS \"$f0\" > FROM \"foodmart\".\"product\") AS \"t0\" ON TRUE > WHERE \"product\".\"brand_name\" = \"t0\".\"$f0\" {code} > PostgreSQL Dialect will generate SQL: > {code:java} > SELECT "product"."product_class_id" AS "C" > FROM "foodmart"."product" > LEFT JOIN (SELECT CASE COUNT( > {code} > {color:#009100}*{color} > {code:java} > ) WHEN 0 THEN NULL WHEN 1 THEN MIN("product_name") ELSE (SELECT CAST(NULL AS > VARCHAR(60)) > UNION ALL > SELECT CAST(NULL AS VARCHAR(60))) END AS "$f0" > FROM "foodmart"."product") AS "t0" ON TRUE > WHERE "product"."brand_name" = "t0"."$f0" {code} -- This message was sent by Atlassian Jira (v8.20.10#820010)