生成線性相關的測試資料。
同樣可以用到generate_series和隨機數。
例子 生成10萬條隨機數字。
select trunc(10000 + 1000000*random()) id from generate_series(1,100000);
根據剛才那組資料,加減5以內的隨機數,生成另一組數字。
select id, trunc(id + 5-random()*10) from
(select trunc(10000 + 1000000*random()) id from generate_series(1,100000)) t;
如下
postgres=# create table corr_test(c1 int, c2 int);
create table
postgres=# insert into corr_test select id, trunc(id + 5-random()*10) from (select trunc(10000 + 1000000*random()) id from generate_series(1,100000)) t;
insert 0 100000
postgres=# select corr(id, trunc(id + 5-random()*10)) from (select trunc(10000 + 1000000*random()) id from generate_series(1,100000)) t;
corr
-------------------
0.999999999954681
(1 row)
... ...
postgres=# select corr(id, trunc(id + 5-random()*10)) from (select trunc(10000 + 1000000*random()) id from generate_series(1,100000)) t;
corr
-------------------
0.999999999954898
(1 row)
p元回歸的測試資料也可以使用以上方法生成。 PostgreSQL 中如何delete重複資料
時常有這樣的case db例項執行一段時間後,發現需要給1個table中的某 些 欄位加unique 約束,但建立unique constraints 或 index 時,報出 detail key col value is duplicated 此時就需要先按照一定邏輯將重複資料僅保留1條,將冗餘...
PostgreSQL中如何關閉死鎖的程序
由於使用的postgresql資料庫,沒有資料。只好進行谷歌。最終在乙個英文論壇中發現了解決方法。如下 1.檢索出死鎖程序的id。select from pg stat activity where datname 死鎖的資料庫id 檢索出來的字段中,wating 2.將程序殺掉。select pg...
在ubuntu下安裝PostgreSQL 9 0
最新版的直接可以用命令安裝 sudo apt get install postgresql xx 如果想安裝舊版本的 需要更新一下源 cd etc apt cp sources.list sources.list.old sudo vi sources.list在sources.list追加 deb...