Following on from this question and subsequent answers: Appropriate values for -Infinity & Infinity in Postgres
and the documentation, it seems clear that the real
and double precision
number types support both positive and negative infinity. However, no mention is made for the numeric
type, except that the range
has "no limit".
Are positive and negative infinity supported for numeric
types (in PostgreSQL 9.5), and if so, how does one insert such values?
EDIT (as suggested by @TimBiegeleisen):
The reason this came about is because I am trying to write a numeric column from R
to a database table. The column contains Inf
values, but using dbWriteTable
from RPostgreSQL
errors with:
Error in postgresqlgetResult(new.con) :
RS-DBI driver: (could not Retrieve the result :
ERROR: invalid input syntax for type numeric: "Inf"
In my particular case I can convert Inf
to NA
and write these values as NULL
, but this doesn't work when the column contains missing values, or the not null
condition is imposed in the database. I suppose another thing to do would be to write an arbitrarily large number.
PostgreSQL will support numeric +inf/-inf from v14 🎉
NUMERIC
does not support +-infinity, though it does support NaN. That's rather an unfortunate limitation. Addressing it would probably require changing the on-disk binary format of numeric
which could be challenging...
craig=> SELECT NUMERIC 'NaN';
numeric
---------
NaN
(1 row)
craig=> SELECT NUMERIC '-inf';
ERROR: invalid input syntax for type numeric: "-inf"
LINE 1: SELECT NUMERIC '-inf';
^
craig=> SELECT NUMERIC '+inf';
ERROR: invalid input syntax for type numeric: "+inf"
LINE 1: SELECT NUMERIC '+inf';
craig=> SELECT NUMERIC '+infinity';
ERROR: invalid input syntax for type numeric: "+infinity"
LINE 1: SELECT NUMERIC '+infinity';
^
craig=> SELECT NUMERIC 'infinity';
ERROR: invalid input syntax for type numeric: "infinity"
LINE 1: SELECT NUMERIC 'infinity';
^
craig=> SELECT NUMERIC '-infinity';
ERROR: invalid input syntax for type numeric: "-infinity"
LINE 1: SELECT NUMERIC '-infinity';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With