0
所以我有一個查詢,我試圖獲取列或generic
列中包含單詞citalopram
或單詞celexa
的行。where子句沒有在Postgres查詢中選擇正確的行
首先我想:
where
( medication ilike '%citalopram%' or
generic ilike '%citalopram%' or
medication ilike '%celexa%' or
generic ilike '%celexa%')
,一切都找到和花花公子,除了包含在藥物escitalopram
,它也選擇了行。所以我改變了查詢,以便它看起來像下面這樣:
where
( medication ilike '%citalopram%' or
generic ilike '%citalopram%' or
medication ilike '%celexa%' or
generic ilike '%celexa%') and
medication not ilike '%escitalopram%' and
generic not ilike '%escitalopram%'
現在,果然它消除含escitalopram
行,但現在有時會忽略有行:
- 服藥=
CeleXa 40mg oral tablet
,通用=null
- 藥物=
citalopram 40mg oral tablet
,通用=null
等
不知道爲什麼這可能是問題。任何建議將不勝感激!
這是因爲通用有一個空值 - 值得一讀此HTTPS: //stackoverflow.com/questions/22818070/behaviour-of-not-like-with-null-values –
你可能會更好使用正則表達式進行「整個單詞」搜索,例如'藥物〜*'\ ycelexa \ y'' –