假设我有一个列族
CREATE TABLE cnt_test (time_slot text , comp1 text, comp2 text, field1 counter, field2 counter, PRIMARY KEY(time_slot,comp1, comp2));
现在我试图在其中插入一些数据
UPDATE cnt_test SET field1=field1+1, field2=field2+2 WHERE time_slot='20130924' AND comp1='' AND comp2='ABC';
UPDATE cnt_test SET field1=field1+1, field2=field2+2 WHERE time_slot='20130924' AND comp1='' AND comp2='ABC';
UPDATE cnt_test SET field1=field1+1, field2=field2+2 WHERE time_slot='20130924' AND comp1='' AND comp2='ABC';
UPDATE cnt_test SET field1=field1+1, field2=field2+2 WHERE time_slot='20130924' AND comp1='' AND comp2='XYZ';
UPDATE cnt_test SET field1=field1+1, field2=field2+2 WHERE time_slot='20130924' AND comp1='PQR' AND comp2='';
正如您在上面的语句中看到的,我在复合键部分插入了一些空值,而不是null我正在把blank特点。
我什至可以查询相同的
SELECT * FROM cnt_test WHERE time_slot='20130924' AND comp1='' AND comp2='ABC';
time_slot | comp1 | comp2 | field1 | field2
-----------+-------+-------+--------+--------
20130924 | | ABC | 4 | 8
(1 rows)
SELECT * FROM cnt_test WHERE time_slot='20130924' AND comp1='PQR' AND comp2='';
time_slot | comp1 | comp2 | field1 | field2
-----------+-------+-------+--------+--------
20130924 | PQR | | 1 | 2
(1 rows)
因此,总结一下,只需将空列值替换为空列即可,即''