Skip to content

Infinite arguments require explicit type cast #361

@mmuurr

Description

@mmuurr

Not sure what can be done about this, but if an SQL expression with parameters expects a float and Inf (or -Inf) is passed, PostgreSQL errs and complains like so:

dbGetQuery(conn, "select 0 + $1", Inf)
## Error: Failed to fetch row: ERROR:  invalid input syntax for type integer: "Inf"

With an explicit PostgreSQL type cast for the $1 parameter, however:

dbGetQuery(conn, "select 0 + $1::float", Inf)
## # A tibble: 1 x 1
##   `?column?`
##        <dbl>
## 1        Inf

This mirrors what happens in PostgreSQL:

select 0 + 'Infinity';  -- errs
select 0 + 'Infinity'::float;  -- succeeds

And so I don't think this counts as a bug, but it's sneaky in that a RPostgres user would have to protect her queries with type casts if there was any chance the R program would produce Inf as the passed value. Perhaps explicit casting should always be encouraged anyhow, though :-)

In any case, I don't know if this is known to y'all, and perhaps it's worth mentioning in docs (since PostgreSQL does support infinite values, but just requires this extra care in some situations to prevent errors).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions