【问题标题】:How to insert a python NUMERIC type in postgresql REAL type column如何在 postgresql REAL 类型列中插入 python NUMERIC 类型
【发布时间】:2016-03-02 16:16:51
【问题描述】:

我在 postgresql 中有一个列定义为 REAL[] 类型,当我尝试在该列中插入一个值时,它会导致错误。

值是一个数字数组,像这样:[23.4, -45, 7895]

由此产生的错误是:operator does not exist: real[] = numeric[]

我该怎么办?

【问题讨论】:

  • 恕我直言,最好在 postgres 表中使用numeric 类型。浮点类型很少有用。

标签: python postgresql numeric


【解决方案1】:

我强烈怀疑问题不是您查询的插入部分:

db=# create temp table fnord ( foo numeric[] );
db=# insert into fnord values ('{23.4, -45, 7895}'::real[]);
db=# insert into fnord values ('{23.4, -45, 7895}'::real[]);
db=# select '{23.4, -45, 7895}'::numeric[] = '{12, 12, 12}'::real[];
ERROR:  operator does not exist: numeric[] = real[]
LINE 1: select '{23.4, -45, 7895}'::numeric[] = '{12, 12, 12}'::real...
                                              ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
Time: 77.539 ms

您可能在查询的某处进行了比较。用演员表修复它,你应该没问题。

【讨论】:

  • 是的,我在插入之前有一个比较。所以这就是问题所在,不是插入,而是比较。
猜你喜欢
  • 2014-03-01
  • 1970-01-01
  • 2019-09-09
  • 1970-01-01
  • 2017-12-24
  • 2020-06-10
  • 2014-11-01
  • 2013-06-19
  • 2023-03-16
相关资源
最近更新 更多