我有一個表定義為:
CREATE TABLE IF NOT EXISTS test (
id INT NOT NULL,
depth_mm REAL[]
);
如果我在陣列中插入帶有數字和空值的東西depth_mm,就沒有問題:
INSERT INTO test (id, depth_mm) VALUES (2, ARRAY[1,NULL,NULL]);
但是如果我插入一個值陣列,它會抱怨:
INSERT INTO test (id, depth_mm) VALUES (2, ARRAY[NULL,NULL,NULL]);
ERROR: column "depth_mm" is of type real[] but expression is of type text[]
LINE 1: INSERT INTO test (id, depth_mm) VALUES (2, ARRAY[NULL,NULL,NU...
^
HINT: You will need to rewrite or cast the expression.
如何讓 Postgres 了解我想要插入一個空值陣列?
uj5u.com熱心網友回復:
引擎無法推斷陣列的型別,因為您所擁有的只是 NULL,而 NULL 可以是任何型別。所以你需要通過將它轉換為真實來告訴它它是一個真正的 NULL:
INSERT INTO test (id, depth_mm) VALUES (2, ARRAY[NULL::real,NULL,NULL]);
或者您可以轉換整個陣列:
INSERT INTO test (id, depth_mm) VALUES (2, ARRAY[NULL,NULL,NULL]::real[]);
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/430620.html
標籤:数组 PostgreSQL
上一篇:專案問題-java新手
下一篇:如何使用ifelse條件回圈?
