postgres copy語句的使用

2021-08-02 15:10:24 字數 489 閱讀 1215

工作中,我們經常需要將一張表裡面的資料複製到另外一張表。當然,pg中可以利用pg_dump和pg_restore來做備份與恢復。

但是copy同樣可以做這件事,並且copy用法還比較靈活,可以指定複製內容等。

下面簡單介紹一下:

條件:使用copy做複製與黏貼時需要在超級使用者下,否則會報許可權錯誤。

複製表裡面的內容:

copy (select * from tb_right) to '/home/bsauser/zhubao.csv' (format csv, delimiter ';');

資料已經被複製並儲存在zhubao.csv中了。

若想要將複製的檔案轉存到另一張表:

copy tb_right from 'home/bsauser/zhubao.csv' (format csv, delimiter ';');

結束!!!

Postgres copy命令匯入匯出資料

最近有需要對資料進行遷移的需求,由於postgres效能的關係,單錶3000w的資料量查詢起來有一些慢,需要對大表進行切割,拆成若干個子表,涉及到原有資料要遷移到子表的需求。起初的想法是使用儲存過程,使用select insert方式進行,但是資料量大的時候耗時有點久,於是需要想別的辦法,就發現了p...

python的語句 Python的語句

python中的兩種語句 1 if條件控制語句 格式 if a int input 請輸入第乙個數 b int input 請輸入第二個數 if a b print a比b小 if else a int input 請輸入第乙個數 b int input 請輸入第二個數 if a b print a...

SQL 語句的TOP,Distinct語句

select top 3 from dbo.mystudent 查詢student表中前3條所有的資料 select top 3 s name,s gender,s address,s age from dbo.mystudent 查詢student表中前3條部分的資料 select top 3 p...