You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何DuckDB不能使用temp.duckdb作为文件名?报错解析

DuckDB R库使用temp.duckdb作为文件名的解析错误说明

DuckDB(至少其R语言库duckdb)已保留temp.duckdb作为特殊文件名。若将数据库文件名设为temp.duckdb,会抛出一条不够直观的错误:

Error: Parser Error: Only TEMPORARY table names can use the "temp" catalog

触发错误的示例代码

library("glue")
library("duckdb")
#> Warning: package 'duckdb' was built under R version 4.2.3
#> Loading required package: DBI
#> Warning: package 'DBI' was built under R version 4.2.3
library("dplyr")
#> Warning: package 'dplyr' was built under R version 4.2.3
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

# 将临时目录设为工作目录
setwd(tempdir())

con <- 
    DBI::dbConnect(
        duckdb(),
        dbdir = "temp.duckdb"
    )

duckdb_register(con, "mtcars", mtcars)

# 使用已注册的数据框创建DuckDB本地表(也可使用csv/parquet等)
tbl(con, "mtcars") |> 
    compute(name = "mtcars_native", temporary = FALSE)
#> Error in `db_save_query.DBIConnection()`:
#> ! Can't save query to "mtcars_native".
#> Caused by error:
#> ! rapi_prepare: Failed to prepare query CREATE TABLE 
#> mtcars_native AS
#> SELECT *
#> FROM mtcars
#> Error: Parser Error: Only TEMPORARY table names can use the "temp" catalog

这可能是内存版DuckDB对temp关键字的有意设计,但temp是测试场景下的常用名称,很容易引发使用者困惑,特此记录以供参考。

内容的提问来源于stack exchange,提问作者Imtiaz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 16:01:18