我正在嘗試插入時間戳型別,如果為空字串,則將值設定為NULL.
示例:https : //www.db-fiddle.com/f/p1jQfNGJ8gexUrtZgp5h63/2
但是 null 似乎是錯誤所見的文本型別:
error: column "timestamp_clmn" is of type timestamp without time zone but expression is of type text
如何在時間戳欄位上使用 NULLIF?
uj5u.com熱心網友回復:
從你的例子:
select nullif('','');
nullif
--------
NULL
select pg_typeof(nullif('',''));
pg_typeof
-----------
text
從檔案NULLIF:
結果與第一個引數的型別相同——但有一個微妙之處。實際回傳的是隱含 = 運算子的第一個引數,在某些情況下,它會被提升以匹配第二個引數的型別。例如,NULLIF(1, 2.2) 產生數字,因為沒有 integer = numeric 運算子,只有 numeric = numeric。
所以:
select nullif('','')::timestamp;
nullif
--------
NULL
select pg_typeof(nullif('','')::timestamp);
pg_typeof
-----------------------------
timestamp without time zone
您需要將文本NULL轉換為timestamp(tz)一個。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/340187.html
標籤:PostgreSQL
下一篇:為tsvector列構建統計資訊
