3
如何爲sqlite3中的單個主鍵創建多個條目?這是我發現的問題:如何爲sqlite3中的單個主鍵擁有多個條目?
$ sqlite3 dbName.db
sqlite> .s
CREATE TABLE 'tableName' (
columnOne INTEGER NOT NULL,
columnTwo INTEGER NOT NULL,
columnThree INTEGER NOT NULL,
columnFour INTEGER NOT NULL,
columnFive REAL NOT NULL,
PRIMARY KEY (columnOne, columnTwo, columnThree, columnFour)
);
sqlite> SELECT count(1) AS nb FROM tableName GROUP BY columnOne, columnTwo, columnThree, columnFour HAVING nb > 1;
[A whole bunch of results, some with nb up to 34!]
最新通報 被要求重複條目的示例:
$ sqlite3 observation.db
sqlite> .mode column
sqlite> .s
CREATE TABLE 'observation' (
station INTEGER NOT NULL,
specie INTEGER NOT NULL,
isAvg INTEGER NOT NULL,
date INTEGER NOT NULL,
value REAL NOT NULL,
PRIMARY KEY (station, specie, isAvg, date)
);
sqlite> SELECT * FROM observation WHERE station = 105001 AND specie = 3 AND isAvg = 1 AND date = 1308650400;
station specie isAvg date value
---------- ---------- ---------- ---------- ----------
105001 3 1 1308650400 31.0
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
105001 3 1 1308650400 2.42523266
@mu太短:數據庫是由運行Tcl腳本充滿每小時使用以下查詢之一插入數據:
INSERT OR REPLACE INTO observation (station, specie, isAvg, date, value) VALUES ($stationId, $speciesId, 0, $date, $value);
INSERT OR REPLACE INTO observation (station, specie, isAvg, date, value) VALUES (${stationId}, ${speciesId}, 1, ${date}, ${speciesAvg});
我剛想到別的,我不知道這是否可以幫助...:
sqlite3 observation.db
sqlite> pragma integrity_check;
integrity_check
rowid 53202997 missing from index sqlite_autoindex_observation_1
rowid 53202998 missing from index sqlite_autoindex_observation_1
rowid 53202999 missing from index sqlite_autoindex_observation_1
rowid 53203000 missing from index sqlite_autoindex_observation_1
rowid 53203006 missing from index sqlite_autoindex_observation_1
rowid 53584951 missing from index sqlite_autoindex_observation_1
[...]
and more of the same (100 such lines since integrity_check stops at 100 by default..)
[...]
@mu太短:我編輯了我的原始問題以添加重複數據樣本和用於填充數據庫的查詢。 – Shawn
@mu太短:它發生一次隨機,而不是另一次,而我正在做很多測試,運行一個使用數據庫的特定腳本,看看如果數據庫不存在或爲空會發生什麼......除了這兩次,它已經不可能重現的錯誤..至於數據庫損壞,這是非常可能的,因爲我們有時最終會出現像「數據庫磁盤映像格式錯誤」或「磁盤I/O錯誤」的錯誤..問題是,我們不完全知道這些錯誤來自哪裏。 – Shawn
不,我還沒有考慮過寫作。我想我應該..謝謝畝,我會在這裏發表評論,如果有進展。 – Shawn