PIVOT 不识别引号中的列

PIVOT does not recognise column enclosed in quotes

下面的示例 SQL - 基本上如果我们 运行 这个查询使用 "category" 而不是定义为类别(没有引号)它工作正常。但是下面失败了 SQL compilation error: error line 1 at position 14 invalid identifier '"category"'. 有什么想法吗?

create or replace table monthly_sales(empid int, amount int, month text, "category" text)
    as select * from values
    (1, 10000, 'JAN', 'aaa'),
    (1, 400, 'JAN', 'xxx'),
    (2, 4500, 'JAN', 'aaa'),
    (2, 35000, 'JAN', 'aaa'),
    (1, 5000, 'FEB', 'bbb'),
    (1, 3000, 'FEB', 'bbb'),
    (2, 200, 'FEB', 'bbb'),
    (2, 90500, 'FEB', 'aaa'),
    (1, 6000, 'MAR', 'zzz'),
    (1, 5000, 'MAR', 'aaa'),
    (2, 2500, 'MAR', 'ttt'),
    (2, 9500, 'MAR', 'aaa'),
    (1, 8000, 'APR', 'iii'),
    (1, 10000, 'APR', 'iii'),
    (2, 800, 'APR', 'aaa'),
    (2, 4500, 'APR', 'zzz');

select empid, "category", "'JAN'", "'FEB'", "'MAR'", "'APR'"
  from monthly_sales
    pivot(sum(amount) for month in ('JAN', 'FEB', 'MAR', 'APR'))
      as p
  order by empid;

如果你在你的会话中执行这个,你可以让你的代码工作:

alter session set quoted_identifiers_ignore_case = true;

https://docs.snowflake.net/manuals/sql-reference/parameters.html#quoted-identifiers-ignore-case

编辑:如果您不想这样做,则必须在 select 查询中用单引号将 "category" 括起来:

select empid, '"category"', "'JAN'", "'FEB'", "'MAR'", "'APR'"
  from monthly_sales
    pivot(sum(amount) for month in ('JAN', 'FEB', 'MAR', 'APR'))
      as p
  order by empid;