假设我有一个列族
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我放入了空白字符。
我什至可以查询同一个
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)
所以总结每件事只需用空列替换空列值,即''