如何在 Postgres-Heroku 中从 csv 插入批量数据?

问题描述 投票:0回答:1

我已经使用 dbeaver 将托管的 postgres-db 从 Heroku 连接到本地计算机,连接成功,当我尝试一次插入单个或多个数据(多个数据,但不是批量)时,它确实如此,但是当我确实尝试从 CSV 文件批量插入数据,但失败了,并给出以下错误:

SQL Error [42501]: ERROR: must be superuser or have privileges of the pg_read_server_files role to COPY from a file
  Hint: Anyone can COPY to stdout or from stdin. psql's \copy command also works for anyone

数据看起来像这样:

,title,ingredients,directions,link,source,NER
0,No-Bake Nut Cookies,"[""1 c. firmly packed brown sugar"", ""1/2 c. evaporated milk"", ""1/2 tsp. vanilla"", ""1/2 c. broken nuts (pecans)"", ""2 Tbsp. butter or margarine"", ""3 1/2 c. bite size shredded rice biscuits""]","[""In a heavy 2-quart saucepan, mix brown sugar, nuts, evaporated milk and butter or margarine."", ""Stir over medium heat until mixture bubbles all over top."", ""Boil and stir 5 minutes more. Take off heat."", ""Stir in vanilla and cereal; mix well."", ""Using 2 teaspoons, drop and shape into 30 clusters on wax paper."", ""Let stand until firm, about 30 minutes.""]",www.cookbooks.com/Recipe-Details.aspx?id=44874,Gathered,"[""brown sugar"", ""milk"", ""vanilla"", ""nuts"", ""butter"", ""bite size shredded rice biscuits""]"
1,Jewell Ball'S Chicken,"[""1 small jar chipped beef, cut up"", ""4 boned chicken breasts"", ""1 can cream of mushroom soup"", ""1 carton sour cream""]","[""Place chipped beef on bottom of baking dish."", ""Place chicken on top of beef."", ""Mix soup and cream together; pour over chicken. Bake, uncovered, at 275\u00b0 for 3 hours.""]",www.cookbooks.com/Recipe-Details.aspx?id=699419,Gathered,"[""beef"", ""chicken breasts"", ""cream of mushroom soup"", ""sour cream""]"
2,Creamy Corn,"[""2 (16 oz.) pkg. frozen corn"", ""1 (8 oz.) pkg. cream cheese, cubed"", ""1/3 c. butter, cubed"", ""1/2 tsp. garlic powder"", ""1/2 tsp. salt"", ""1/4 tsp. pepper""]","[""In a slow cooker, combine all ingredients. Cover and cook on low for 4 hours or until heated through and cheese is melted. Stir well before serving. Yields 6 servings.""]",www.cookbooks.com/Recipe-Details.aspx?id=10570,Gathered,"[""frozen corn"", ""cream cheese"", ""butter"", ""garlic powder"", ""salt"", ""pepper""]"

我尝试过的:

我已经在本地 Postgres 实例上检查了此查询是否有效

查询在本地 postgres 实例上运行良好,即 localhost:5432

数据量约2M+

数据仅为文本格式

数据库归我所有,它是heroku的基本postgres实例

sql postgresql heroku cloud bulk-load
1个回答
0
投票

由于您尚未提供您正在使用的确切脚本,因此这里是一个通用答复。

COPY
命令需要运行数据库的计算机上的超级用户权限。 psql
\copy
命令在本地计算机上运行,不需要超级用户权限。如果您可以使用 psql 而不是 DBeaver 这应该可以解决问题。

如果您必须使用 DBeaver,那么您可以使用一个导入向导。像这样找到导入向导:在左侧的数据库导航器中导航到要将数据导入到的表。右键单击表格,选择“导入数据”,然后按照向导操作。

© www.soinside.com 2019 - 2024. All rights reserved.