【问题标题】:How to append new data to the log file in PostgreSQL如何将新数据附加到 PostgreSQL 中的日志文件
【发布时间】:2019-10-01 02:43:33
【问题描述】:

我正在将 oracle 代码迁移到 postgresql,我需要将查询附加到现有日志文件。

基本上我想要在 PostgreSQL 中等效于 oracle 命令“SPOOL test.log APPEND”。有没有办法做到这一点?

我尝试使用 \o 或 \o+ 将新数据附加到日志文件或在 PostgreSQL 中复制,但它会覆盖日志文件。

我的代码是这样的:

甲骨文:

spool test.log
select  uid from users where uid='1111';
spool off

select sysdate from dual;   
//other business logic code
                                                      -
spool test.log append
select balance from balances where uid='1111';
spool off

Postgresql:

\o test.log
select  uid from users where uid='1111';
\o

select current_date;  
//other business logic code
                                                       -
\o test.log  
select balance from balances where uid='1111';
\o

我希望 \o 块中的两个查询附加到 PostgreSQL 中的同一个文件。

【问题讨论】:

    标签: postgresql database-migration plpgsql


    【解决方案1】:

    你可以使用

    \o | cat >> test.log
    

    在 UNIX 平台上。

    【讨论】:

      猜你喜欢
      • 2015-10-17
      • 1970-01-01
      • 1970-01-01
      • 2011-01-28
      • 1970-01-01
      • 2013-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多