我是 PostgreSQL 新手,我一直在學習。我正在遵循使用 MySQL 的小型專案指南,但我更喜歡在 PostgreSQL 中作業。我已經閱讀了許多過去對我有幫助的 StackOverflow 答案,但我完全堅持這一點。我的代碼是:
Select a.parcelid, a.propertyaddress, b.parcelid, b.propertyaddress,
ISNULL(a.propertyaddress, b.propertyaddress)
From public.nashhousing a
JOIN public.nashhousing b
on a.parcelid = b.parcelid
AND a.uniqueid <> b.uniqueid
Where a.propertyaddress is null
我不斷收到的錯誤訊息是:
ERROR: function isnull(text, text) does not exist
LINE 2: ISNULL(a.propertyaddress, b.propertyaddress)
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
誰能幫助我?謝謝!
uj5u.com熱心網友回復:
COALESCE是這個函式的 sql 標準版本,可能適用于大多數資料庫。IE,coalesce(a.propertyaddress, b.propertyaddress)
COALESCE 回傳第一個非空值,因此它可以使用兩個(如您的情況)或更多值。例如,我們也可以寫coalesce(a.propertyaddress, b.propertyaddress, 'no address!'),如果前兩個都為空,它將回傳第三個值。
這是官方的 postgres 檔案:
https://www.postgresql.org/docs/current/functions-conditional.html#FUNCTIONS-COALESCE-NVL-IFNULL
uj5u.com熱心網友回復:
我認為您的示例是錯誤的,因為您正在尋找IFNULL而不是ISNULL的替代方法,因為ISNULL它只需要一個引數。備用和 SQL 標準函式是COALESCE。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/514693.html
