R语言 示例化CTE的duckdb语法错误

sz81bmfz  于 2023-10-13  发布在  其他
关注(0)|答案(1)|浏览(132)

我试图用物化CTE创建一个查询,但我得到了一个语法错误(在这个例子中是用R,但问题与R无关,我希望...)。
抛出错误的查询如下所示(非常接近文档中给出的示例)

WITH avg_cte AS MATERIALIZED (
  SELECT carrier, MEAN(dep_delay) AS avg_dep_delay
  FROM flights
  GROUP BY carrier
)
SELECT * FROM avg_cte

带有R的MWE看起来像这样

cc <- DBI::dbConnect(duckdb::duckdb())
DBI::dbWriteTable(cc, "flights", nycflights13::flights)

q <- "WITH avg_cte AS MATERIALIZED (
  SELECT carrier, MEAN(dep_delay) AS avg_dep_delay
  FROM flights
  GROUP BY carrier
)
SELECT * FROM avg_cte
"
DBI::dbGetQuery(cc, q)
#> Error: Parser Error: syntax error at or near "MATERIALIZED"
#> LINE 1: WITH avg_cte AS MATERIALIZED (
sczxawaw

sczxawaw1#

MATERIALIZE关键字是0.9.0中的新关键字,但当前的R包仍然只有0.8.1-3。“出血边缘”installation instructions应该允许在此期间安装0.9.0。

install.packages('duckdb', repos=c('https://duckdb.r-universe.dev', 'https://cloud.r-project.org'))

相关问题