PostgreSQL 复制命令给出临时错误 table

PostgreSQL copy command gives error for temporary table

我正在尝试 运行 在 unix 控制台上执行以下命令:

env 'PGOPTIONS=-c search_path=admin -c client_min_messages=error' psql -h hostname -U user -p 1111 -d platform -c "CREATE TEMP TABLE admin.tmp_213 AS SELECT * FROM admin.file_status limit 0;\copy admin.tmp_213(feed_id,run_id,extracted_date,file_name,start_time,file_size,status,crypt_flag)  FROM '/opt/temp/213/list.up' delimiter ',' csv;UPDATE admin.file_status SET file_size = admin.tmp_213.file_size FROM  admin.tmp_213 A WHERE  admin.file_status.feed_id = A.feed_id and admin.file_status.file_name = A.file_name;"

我收到以下错误:

ERROR:  syntax error at or near "\"
LINE 1: ...* FROM admin.file_status limit 0;\copy admi...

如果我在 COPY 之前使用没有反斜杠的上述命令,它会出现以下错误:

ERROR:  cannot create temporary relation in non-temporary schema

我正在执行上述操作以实现此处提到的解决方案: How to update selected rows with values from a CSV file in Postgres?

您的第一个错误是因为像 \copy 这样的元命令在与 -c 一起给出时不能与常规命令组合在同一行中。您可以提供两个 -c 选项,每个选项有一个命令。

第二个错误是不言自明的。您无法决定您的 temp table 进入哪个模式。只需省略架构。