如何在 Postgres 中将数据从 csv 文件复制到名称为 table 的用户?

How to copy data from csv file into table with name user in Postgres?

我正在尝试将用户信息从 csv 文件复制到 Postgres 数据库中,table 名称是 user

我可以手动从 pgAdmin 导入数据。但是,如果我 运行 COPY user(columns) FROM csvfile... 命令,它会在 user.

处给我语法错误

有解决办法吗?

当我将 user table 重命名为 usert 时,它起作用了,我能够插入数据。

问题是因为 table 名字吗?

user是保留关键字。因此,您必须将 table 标识符指定为 带引号的标识符 它用双引号引起来:

COPY "user" (columns) FROM csvfile...

有关更多信息,请参阅 Lexical Structure, specifically the section Identifiers and Key Words 上的文档。