2013-06-28 21 views
0

红移不同ILIKE我跑在亚马逊红移以下三个疑问:ILIKE而不是在AWS从总

select count(*) 
from t1 

的计数1554

select count(*) 
from t1 
where 
    item_name ilike "blue" 

计数为62

select count(*) 
from t1 
where 
    item_name not ilike "blue" 

计数为85.

最后两个(62 + 85)应该等于1554.我错过了什么?

回答

1

双引号是标识符:"myColumn"
单引号的值为:'value'

你的例子与那些basic syntax rules相矛盾。

此外,您没有考虑NULL值,这既不符合

item_name ilike 'blue' 

资格,也不符合

item_name not ilike 'blue' 

你怎么获得:

SELECT count(*)        AS all_rows 
    , count(item_name ~~* 'blue' OR NULL) As item_name_blue 
    , count(item_name !~~* 'blue' OR NULL) As item_name_not_blue 
    , count(item_name)      AS item_name_not_null 
    , count(item_nameIS NULL OR NULL)  AS item_name_null 
FROM t1; 

~~* ..内部Postgres运算符简写为LIKE
!~~* ..为NOT ILIKE
Postgres内部操作者速记(小心:稍有不同操作者优先。)

+0

感谢。双引号是这个问题中的一个错字。一旦我添加了空白,弥补了差异。 – Elm