postgres导入excel_将数据从Excel导入PostgreSQL

在尝试将CSV格式的Excel文件导入PostgreSQL时遇到'权限被拒绝'错误。创建了名为allfields的表并匹配了Excel列名。问题在于文件路径,需将其移动到公共可访问的文件夹,如C:\Users\Public,以解决Windows权限问题。
摘要由CSDN通过智能技术生成

bd96500e110b49cbb3cd949968f18be7.png

I have seen questions on stackoverflow similar/same as the one I am asking now, however I couldn't manage to solve it in my situation.

Here is the thing:

I have an excel spreadsheet(.xlsx) whom i converted in comma seperated value(.CSV) as it is said in some answers:

My excel file looks something like this:

--------------------------------------------------

name | surname | voteNo | VoteA | VoteB | VoteC

--------------------------------------------------

john | smith | 1001 | 30 | 154 | 25

--------------------------------------------------

anothe| person | 1002 | 430 | 34 | 234

--------------------------------------------------

other | one | 1003 | 35 | 154 | 24

--------------------------------------------------

john | smith | 1004 | 123 | 234 | 53

--------------------------------------------------

john | smith | 1005 | 23 | 233 | 234

--------------------------------------------------

In PostgreSQL I created a table with name allfields and created 6 columns

1st and 2nd one as a character[] and last 4 ones as integers with the same name as shown in the excel table (name, surname, voteno, votea, voteb, votec)

Now I'm doing this:

copy allfields from 'C:\Filepath\filename.csv';

But I'm getting this error:

could not open file "C:\Filepath\filename.csv" for reading: Permission denied

SQL state: 42501

My questions are:

Should I create those columns in allfields table in PostgreSQL?

Do I have to modify anything else in Excel file?

And why I get this 'permission denied' error?

解决方案

Ok the Problem was that i need to change the path of the Excel file. I inserted it in the public account where all users can access it.

If you face the same problem move your excel file to ex C:\\User\Public folder (this folder is a public folder without any restrictions), otherwise you have to deal with Windows permission issues.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值