Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-5711

Implement the SINGLE_VALUE aggregation in PostgreSQL Dialect

    XMLWordPrintableJSON

Details

    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:

      select "product_class_id" as c
      from "product" where  "brand_name" = (select "product_name" from "product") 

      PostgreSQL Dialect now generates SQL:

      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\" 

      PostgreSQL Dialect will generate SQL:

      SELECT "product"."product_class_id" AS "C"
      FROM "foodmart"."product"
      LEFT JOIN (SELECT CASE COUNT(*) 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" 

      Attachments

        Issue Links

          Activity

            People

              nobigo xiong duan
              nobigo xiong duan
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: