Skip to content

money columns are read as 0 #654

Done

Description

@krlmlr

Every value of a money column is read as 0. PostgreSQL sends money in text form with a currency symbol and thousands separators ($1,234.56), and RPostgres parses it as a double with atof(), which stops at the $ and returns 0. This is not Arrow-specific; Arrow results inherit it.

Location: RPostgres, PqColumnDataSource::fetch_real().

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())
dbGetQuery(con, "SELECT 1::money AS m, 1234.56::money AS n")
#>   m n
#> 1 0 0
# Expected: 1 and 1234.56 (or the strings "$1.00" and "$1,234.56")
dbGetQuery(con, "SELECT pg_typeof(1::money)::text, 1234.56::money::text")
#>   pg_typeof      text
#> 1     money $1,234.56

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"), dependencies = FALSE))[c("package", "ondiskversion", "source")]
#>             package ondiskversion         source
#> DBI             DBI         1.3.0           RSPM
#> RPostgres RPostgres        1.4.10 RSPM (R 4.5.0)

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

  • decide: parse money as a number (the format depends on lc_monetary) or return it as a string
  • fix
  • test

Severity: medium (proposed, Kirill may change). Silently wrong values for a rarely used type.

Native Arrow support is coordinated in #631; it is not expected to fix this by construction, since it reuses the fetch path unless it parses the values itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions