1. 程式人生 > 實用技巧 >【ClickHouse問題】更新表字段型別為Nullable(Int32)的列值,最終結果都是固定一個值:93147008???

【ClickHouse問題】更新表字段型別為Nullable(Int32)的列值,最終結果都是固定一個值:93147008???

問題描述:

clickhouse更新表資料。更新的列資料型別是Nullable(Int32),不管更新為什麼數值,最後查詢的結果都是一個固定值:93147008

問題復現:

1:建一張測試表

CREATE TABLE sys_user_menu_relationships_test2
(
    `id` Int32,
    `userId` Nullable(String),
    `rightId` Nullable(Int32),
    `onlyread`  Int32,
    `selectFlag` Int32,
    `insertFlag` Nullable(Int32),
    `deleteFlag` Nullable(Int32),
    `updateFlag` Nullable(Int32),
    `downloadFlag` Nullable(Int32)
)
ENGINE 
= MergeTree ORDER BY id SETTINGS index_granularity = 8192;

2:插入幾條資料

INSERT INTO sys_user_menu_relationships_test2(id,userId,rightId ,onlyread ,selectFlag ,insertFlag,deleteFlag ,updateFlag ,downloadFlag ) VALUES (1,'101',1,2,3,4,5,6,7);
INSERT INTO sys_user_menu_relationships_test2(id,userId,rightId ,onlyread ,selectFlag ,insertFlag,deleteFlag ,updateFlag ,downloadFlag ) VALUES (2
,'102',1,2,3,4,5,6,7); INSERT INTO sys_user_menu_relationships_test2(id,userId,rightId ,onlyread ,selectFlag ,insertFlag,deleteFlag ,updateFlag ,downloadFlag ) VALUES (3,'103',1,2,3,4,5,6,7); INSERT INTO sys_user_menu_relationships_test2(id,userId,rightId ,onlyread ,selectFlag ,insertFlag,deleteFlag ,updateFlag ,downloadFlag ) VALUES (4
,'104',1,2,3,4,5,6,7); INSERT INTO sys_user_menu_relationships_test2(id,userId,rightId ,onlyread ,selectFlag ,insertFlag,deleteFlag ,updateFlag ,downloadFlag ) VALUES (5,'105',1,2,3,4,5,6,7); INSERT INTO sys_user_menu_relationships_test2(id,userId,rightId ,onlyread ,selectFlag ,insertFlag,deleteFlag ,updateFlag ,downloadFlag ) VALUES (6,'106',1,2,3,4,5,6,7);

3:查詢資料

SELECT *
FROM sys_user_menu_relationships_test2

┌─id─┬─userId─┬─rightId─┬─onlyread─┬─selectFlag─┬─insertFlag─┬─deleteFlag─┬─updateFlag─┬─downloadFlag─┐
│  61061234567 │
└────┴────────┴─────────┴──────────┴────────────┴────────────┴────────────┴────────────┴──────────────┘
┌─id─┬─userId─┬─rightId─┬─onlyread─┬─selectFlag─┬─insertFlag─┬─deleteFlag─┬─updateFlag─┬─downloadFlag─┐
│  11011234567 │
│  21021234567 │
│  31031234567 │
│  41041234567 │
│  51051234567 │
└────┴────────┴─────────┴──────────┴────────────┴────────────┴────────────┴────────────┴──────────────┘

6 rows in set. Elapsed: 0.005 sec. 

4:更新Int32列selectFlag (能正常更新,沒有異常)

centf8118.sharding1.db :) ALTER TABLE sys_user_menu_relationships_test2 update selectFlag = 12 where id = 1;

ALTER TABLE sys_user_menu_relationships_test2
    UPDATE selectFlag = 12 WHERE id = 1


Ok.

0 rows in set. Elapsed: 0.003 sec. 

centf8118.sharding1.db :) SELECT * FROM sys_user_menu_relationships_test2;

SELECT *
FROM sys_user_menu_relationships_test2

┌─id─┬─userId─┬─rightId─┬─onlyread─┬─selectFlag─┬─insertFlag─┬─deleteFlag─┬─updateFlag─┬─downloadFlag─┐
│  61061234567 │
└────┴────────┴─────────┴──────────┴────────────┴────────────┴────────────┴────────────┴──────────────┘
┌─id─┬─userId─┬─rightId─┬─onlyread─┬─selectFlag─┬─insertFlag─┬─deleteFlag─┬─updateFlag─┬─downloadFlag─┐
│  110112124567 │
│  21021234567 │
│  31031234567 │
│  41041234567 │
│  51051234567 │
└────┴────────┴─────────┴──────────┴────────────┴────────────┴────────────┴────────────┴──────────────┘

6 rows in set. Elapsed: 0.006 sec. 

5:更新Nullable(Int32)列downloadFlag (見證奇蹟的時刻,注意這次更新的值為12)

centf8118.sharding1.db :) ALTER TABLE sys_user_menu_relationships_test2 update downloadFlag= 12 where id = 3;

ALTER TABLE sys_user_menu_relationships_test2
    UPDATE downloadFlag = 12 WHERE id = 3


Ok.

0 rows in set. Elapsed: 0.003 sec. 

centf8118.sharding1.db :) SELECT * FROM sys_user_menu_relationships_test2;

SELECT *
FROM sys_user_menu_relationships_test2

┌─id─┬─userId─┬─rightId─┬─onlyread─┬─selectFlag─┬─insertFlag─┬─deleteFlag─┬─updateFlag─┬─downloadFlag─┐
│  61061234567 │
└────┴────────┴─────────┴──────────┴────────────┴────────────┴────────────┴────────────┴──────────────┘
┌─id─┬─userId─┬─rightId─┬─onlyread─┬─selectFlag─┬─insertFlag─┬─deleteFlag─┬─updateFlag─┬─downloadFlag─┐
│  110112124567 │
│  21021234567 │
│  310312345693147008 │
│  41041234567 │
│  51051234567 │
└────┴────────┴─────────┴──────────┴────────────┴────────────┴────────────┴────────────┴──────────────┘

6 rows in set. Elapsed: 0.006 sec. 

更新完之後,就看到id = 3的downloadFlag列那個值是:93147008

6:再更新Nullable(Int32)列 updateFlag (見證奇蹟的時刻2,注意這次更新的值為34)

centf8118.sharding1.db :) ALTER TABLE sys_user_menu_relationships_test2 update updateFlag= 34 where id = 3;

ALTER TABLE sys_user_menu_relationships_test2
    UPDATE updateFlag = 34 WHERE id = 3


Ok.

0 rows in set. Elapsed: 0.004 sec. 

centf8118.sharding1.db :) SELECT * FROM sys_user_menu_relationships_test2;

SELECT *
FROM sys_user_menu_relationships_test2

┌─id─┬─userId─┬─rightId─┬─onlyread─┬─selectFlag─┬─insertFlag─┬─deleteFlag─┬─updateFlag─┬─downloadFlag─┐
│  61061234567 │
└────┴────────┴─────────┴──────────┴────────────┴────────────┴────────────┴────────────┴──────────────┘
┌─id─┬─userId─┬─rightId─┬─onlyread─┬─selectFlag─┬─insertFlag─┬─deleteFlag─┬─updateFlag─┬─downloadFlag─┐
│  110112124567 │
│  21021234567 │
│  3103123459314700893147008 │
│  41041234567 │
│  51051234567 │
└────┴────────┴─────────┴──────────┴────────────┴────────────┴────────────┴────────────┴──────────────┘

6 rows in set. Elapsed: 0.009 sec. 

問題來了,為什麼資料型別為Nullable(Int32)列,更新的時候不管怎麼更新都是固定的一個值:93147008???

有哪位大神知道為啥???