postgresql - COPY 命令不返回行数

标签 postgresql psql postgresql-9.4

我有两个都运行 PG 9.4 的数据库实例

当我在一个数据库中发出COPY命令时,它将返回受影响的行数,但是在设置相同的第二个数据库中它不会返回。

我在配置中没有看到任何不同或可能影响的内容。导入不会出错,并且在两个帐户上都成功导入。

Documentation声明只要它不是标准输出就应该返回。

文档中的这一行看起来相关,但我不确定它是否适用于我的情况。

Do not confuse COPY with the psql instruction \copy. \copy invokes COPY FROM STDIN or COPY TO STDOUT, and then fetches/stores the data in a file accessible to the psql client. Thus, file accessibility and access rights depend on the client rather than the server when \copy is used.

我发出的命令是:

COPY [tablename] from '/var/lib/pgsql/datafile.csv'

目前我正在研究 Putty session 变量,但我不确定这是正确的方法。

有人知道为什么会发生这种情况吗?

最佳答案

当 psql 安静时,它不会显示这些消息。

使用-q\set QUIET on激活安静模式

示例:

test=# copy test to '/tmp/foo';
COPY 8
test=# \set QUIET on
test=# copy test to '/tmp/foo';
test=# 

关于postgresql - COPY 命令不返回行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48155993/

相关文章:

sql - 我们如何将所有 PostgreSQL 输出(包括错误)写入日志文件?

sql - 从 sql 文件恢复单个表转储

json - Postgresql - 更新 JSONB 列类型的 SQL

python - 如何创建一个执行插入但该函数必须处理具有不同列数的表的函数?

sql-server - SQL Server 如何强制获取锁?

java - 如何使用ProcessBuilder进行交互式命令?

Postgresql 9.6 varchar 的串联

mysql - 如何根据搜索关键字rails从2个表中获取数据

sql - 使用 postgresql 进行表设计

python - 心理学/Postgres : Connections hang out randomly