2017-07-31 147 views
1

我想導入/複製我的CSV文件到PostgreSQL。但是,我遇到了這些錯誤。我沒有文件的導入/寫入權限。將標準提供幫助和如何?Postgres文檔沒有提供任何示例。我從此被要求進行批量插入,但由於列數據類型太多,我不確定如何進一步處理。將csv文件導入/複製到PostgreSQL中|文件不在本地服務器

命令複製csv文件:

COPY sales.sales_tickets 
FROM 'C:/Users/Nandini/Downloads/AIG_Sales_Tickets.csv' 
DELIMITER ',' CSV; 

ERROR: must be superuser to COPY to or from a file
Hint: Anyone can COPY to stdout or from stdin. psql's \copy command also works for anyone.
1 statement failed.

命令執行批量插入過一次服用:

insert into sales.sales_ticket values (1,'2',3,'4','5',6,7,8,'9',10','11'); 

請建議。謝謝。

回答

0

PostgreSQL docummentation on COPY:

COPY naming a file or command is only allowed to database superusers, since it allows reading or writing any file that the server has privileges to access.

Files named in a COPY command are read or written directly by the server, not by the client application. Therefore, they must reside on or be accessible to the database server machine, not the client. They must be accessible to and readable or writable by the PostgreSQL user (the user ID the server runs as), not the client. Similarly, the command specified with PROGRAM is executed directly by the server, not by the client application, must be executable by the PostgreSQL user. COPY naming a file or command is only allowed to database superusers, since it allows reading or writing any file that the server has privileges to access.

你試圖使用COPY命令違反了兩個要求:

  1. 你試圖執行COPY來自非超級用戶的命令。
  2. 您正在嘗試讀取客戶端計算機上的文件,並將其複製到服務器。

這是行不通的。如果您需要執行此類COPY,您需要:

  1. 將CSV文件複製到服務器;到一個可由執行PostgreSQL服務器進程的(系統)用戶讀取的目錄。
  2. 從超級用戶帳戶執行COPY命令。

替代

如果你不能做的一些,你總是可以使用這樣的工具,pgAdmin 4,並使用其Import/Export functionality

另請參見How to import CSV file data into a PostgreSQL table?

相關問題