如何将 Infinity 值插入 DuckDB 中的 REAL/FLOAT4 列?

How do I insert Infinity values into REAL/FLOAT4 Columns in DuckDB?

假设我有一个名为 table_1 的 table,其中有一个名为 col_1 的列,在 DuckDB 中属于 REAL/FLOAT4 类型。如何将 -Infinity、NaN 和 Infinity 等特殊浮点值插入 col_1?我尝试过以多种不同的方式插入这些值,例如“infinity”、“+infinity”、“inf”、“+inf”等,但没有成功。我能够获取要插入到 PostgreSQL table 中的值,但不能使用 DuckDB,即使它们在其网页上对使用和更新这些值的描述相同。例如,这里有一些示例插入语句在我的 PostgreSQL table 中使用 REAL 列,但在我的 DuckDB table.

中不起作用
INSERT INTO table_1 VALUES ('Infinity');
INSERT INTO table_1 VALUES ('-Infinity');
INSERT INTO table_1 VALUES ('NaN');

如果我在我的 DuckDB table 中使用 REAL/FLOAT4 列尝试这些查询,我会收到与此类似的错误。

Conversion Error: Could not convert string 'Infinity' to FLOAT

下面是DuckDB对特殊浮点值的描述。我还发布了指向数字类型的两个数据库描述的链接,其中包括有关特殊浮点值的描述。

"In addition to ordinary numeric values, the floating-point types have several special values:

Infinity -Infinity NaN

These represent the IEEE 754 special values “infinity”, “negative infinity”, and “not-a-number”, respectively. (On a machine whose floating-point arithmetic does not follow IEEE 754, these values will probably not work as expected.) When writing these values as constants in an SQL command, you must put quotes around them, for example: UPDATE table SET x = '-Infinity'. On input, these strings are recognized in a case-insensitive manner."

DuckDB 数字 https://duckdb.org/docs/sql/data_types/numeric

PostgreSQL 数字 https://www.postgresql.org/docs/current/datatype-numeric.html

在 DuckDB 中,我们不允许在列中存储特殊的浮点数。

它只会使一些算法复杂化,并且(我听说)SQL 标准在技术上不允许这样做(尽管我自己从未验证过)。