When package duckdb is installed from CRAN, it does not contain the JSON extension. Subsequently queries such as below or with nodbi::docdb_query() trigger the Error: rapi_prepare: Failed to prepare query. Under MS Windows and after the JSON extension is installed, loading it often crashes R such as in RStudio; in macOS loading and installing the extension works alright.
> install.packages('duckdb')
> library(duckdb)
Loading required package: DBI
> drv <- duckdb()
> con <- dbConnect(drv)
> dbExecute(con, 'CREATE TABLE tbl (j JSON);')
[1] 0
> dbExecute(con, 'INSERT INTO tbl VALUES (\'{"family": "anatidae", "species": [ "duck", "goose"] }\');')
[1] 1
> dbGetQuery(con, 'SELECT json_type(j) FROM tbl;')
Error: rapi_prepare: Failed to prepare query SELECT json_type(j) FROM example;
Error: Catalog Error: Function with name json_type is not on the catalog, but it exists in the json extension.
To Install and Load the extension, run: INSTALL json; LOAD json;
> dbExecute(con, 'INSTALL json;')
[1] 0
> dbExecute(con, 'LOAD json;')
# Crash of R session
Solution: Install duckdb in R using this command which does not require to separately load and install the JSON extension but works out of the box (v0.6.0 as of 2022-12-03):
When package
duckdb
is installed from CRAN, it does not contain theJSON
extension. Subsequently queries such as below or withnodbi::docdb_query()
trigger theError: rapi_prepare: Failed to prepare query
. Under MS Windows and after theJSON
extension is installed, loading it often crashesR
such as in RStudio; in macOS loading and installing the extension works alright.Solution: Install
duckdb
inR
using this command which does not require to separately load and install theJSON
extension but works out of the box (v0.6.0 as of 2022-12-03):