Writing struct or data frame columns fails with a confusing COPY error

オープン 初心者向け
#649 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
77/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
postgresql, r

調査の方向性

R/dbDataType_PqConnection.RのdbDataType()と、R/tables.Rのsql_data_copy()におけるリストのエンコードから始めてください。issueでは、失敗する両方の経路が説明されています。dbWriteTable()とdbWriteTableArrow()の既存のテストを確認し、struct列とdata frame列のテストを追加してください。両方の経路で、これらの列が未対応であることを明確に示すエラーとともに拒否されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

bug

Writing an Arrow struct column with dbWriteTableArrow(), or a data frame column with dbWriteTable(), creates a column typed after the inner column (integer here) and then fails in COPY with "invalid input syntax for type integer", which does not say what is wrong.

Location: RPostgres, dbDataType() on a data frame returns the types of its columns, so a nested data frame column gets its inner column's type; the encoding then treats the column as a list (sql_data_copy()).

Reprex against the CRAN release (the output on main at 41cd4be is the same):

Sys.setenv(PGHOST = "localhost", PGPORT = "5432", PGUSER = "runner", PGPASSWORD = "test123", PGDATABASE = "testdb")
library(DBI)
con <- dbConnect(RPostgres::Postgres())
tbl <- arrow::arrow_table(x = arrow::Array$create(data.frame(a = 1:2)))
dbWriteTableArrow(con, "t_struct", tbl, overwrite = TRUE)
#> Error:
#> ! COPY returned error : ERROR:  invalid input syntax for type integer: "\x12"
#> CONTEXT:  COPY t_struct, line 1, column x: "\x12"
# Expected: an error that says struct columns are not supported
dbRemoveTable(con, "t_struct", fail_if_missing = FALSE)

# Same with a data frame column
df <- data.frame(id = 1:2)
df$x <- data.frame(a = 1:2)
dbWriteTable(con, "t_struct", df, overwrite = TRUE)
#> Error:
#> ! COPY returned error : ERROR:  invalid input syntax for type integer: "\x12"
#> CONTEXT:  COPY t_struct, line 1, column x: "\x12"
dbRemoveTable(con, "t_struct", fail_if_missing = FALSE)
#> NOTICE:  table "t_struct" does not exist, skipping

dbGetQuery(con, "SHOW server_version")
#>                          server_version
#> 1 16.15 (Ubuntu 16.15-0ubuntu0.24.04.1)
dbDisconnect(con)
as.data.frame(sessioninfo::package_info(c("RPostgres", "DBI", "nanoarrow", "arrow"), dependencies = FALSE))[c("package", "ondiskversion", "source")]
#>             package ondiskversion         source
#> arrow         arrow      26.0.1.1           RSPM
#> DBI             DBI         1.3.0           RSPM
#> nanoarrow nanoarrow         0.9.0           RSPM
#> RPostgres RPostgres        1.4.10 RSPM (R 4.5.0)

Created on 2026-11-29 with reprex v2.1.1

  • fix (a clear error for struct and data frame columns)
  • test

Severity: low (proposed, Kirill may change). It fails loudly, only the message is unclear.

Native Arrow support is coordinated in https://github.com/r-dbi/RPostgres/pull/631; it is not expected to fix this by construction. The native create should reject struct columns with a clear message, and the data frame path stays as it is.

主要言語
R
スター
345
フォーク
81
平均マージ
8時間 21分
マージ済み PR(30日)
18

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

r-dbi/RPostgres のほかの issue

r-dbi/RPostgres の issue をすべて見る

似ている issue

R の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。