2016-03-02 50 views
0

我在postgresql中有一列定義爲REAL []類型,當我嘗試在列中插入值時會導致錯誤。如何在postgresql REAL類型列中插入python NUMERIC類型

值是數字數組,像這樣:[23.4, -45, 7895]

而產生的錯誤是:operator does not exist: real[] = numeric[]

我應該怎麼辦?

+0

恕我直言,最好在postgres表中使用'數字'類型。浮點類型很少用。 –

回答

0

我強烈懷疑這不是你查詢的insert部分這就是問題所在:

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 

你可能有一個比較某處查詢。用劇組修復,你應該沒問題。

+0

是的,我在插入前有一個比較。所以這就是問題所在,不是插入而是比較。 – Falcoa

相關問題