Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从SQL文件更新单个Heroku PostgreSQL表_Sql_Postgresql_Heroku_Heroku Postgres - Fatal编程技术网

从SQL文件更新单个Heroku PostgreSQL表

从SQL文件更新单个Heroku PostgreSQL表,sql,postgresql,heroku,heroku-postgres,Sql,Postgresql,Heroku,Heroku Postgres,我试图在Heroku postgresql中将一个sql文件导入到1个表中 我的答案如下: 这意味着该行存在,因此无法复制 我想到了以下几点 ALTER TABLE products RENAME to original_products CREATE TABLE products; # import data, and drop original_products after checking DROP TABLE original_products 然而,我不知道潜在的副作用是什么。我更喜

我试图在Heroku postgresql中将一个sql文件导入到1个表中

我的答案如下:

这意味着该行存在,因此无法复制

我想到了以下几点

ALTER TABLE products RENAME to original_products
CREATE TABLE products;
# import data, and drop original_products after checking
DROP TABLE original_products
然而,我不知道潜在的副作用是什么。我更喜欢一个不掉桌子的解决方案


我想要的是用sql文件数据替换整个products表。我该怎么做?谢谢

您必须在某个时候删除旧表或删除旧数据。这应该回答你的问题:取决于你想要得到什么。从文件中复制表或合并两个源。在任何情况下,你都不应该在完全确定之前就放弃。你可以在一天、一周、一年之后的任何时候放下你的桌子。
ERROR:  duplicate key value violates unique constraint "products_pkey"
DETAIL:  Key (id)=(1) already exists.
CONTEXT:  COPY products, line 1
ALTER TABLE products RENAME to original_products
CREATE TABLE products;
# import data, and drop original_products after checking
DROP TABLE original_products