官方文檔描述
E.5. Release 12 E.5.3. Changes E.5.3.3. Utility Commands
Add a WHERE clause to COPY FROM to control which rows are accepted (Surafel Temesgen)
This provides a simple way to filter incoming data.
refRelease 12
示例
創建測試表
CREATE TABLE test_copy(id int ,name varchar,insert_time timestamp(0) without time zone default clock_timestamp());
INSERT INTO test_copy(id,name) select n,n||'_test' from generate_series(1,1000) n;
ALTER TABLE test_copy ADD PRIMARY KEY (id);
導出表數據
COPY (SELECT * FROM test_copy WHERE id < 101) TO '/tmp/test_copy_100';
創建目標表
CREATE TABLE test_copy2 (like test_copy);
導入數據(使用where限定)
COPY test_copy2 from '/tmp/test_copy_100' where id<10;
此時數據依據where條件進行了過濾,將過濾後的數據導入到數據庫中。