postgresql - 如何将新数据附加到 PostgreSQL 中的日志文件
问题描述
我正在将 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 中的同一个文件。
解决方案
你可以使用
\o | cat >> test.log
在 UNIX 平台上。
推荐阅读
- oracle - Oracle 数据库网络服务使用的连接字符串
- mysql - 有没有办法在另一个函数中运行 mysql json 函数?
- r - 在具有多个参数的data.frame(data.table)中使用多列的函数
- vsto - 从 COM 加载项窗口中选择 [删除] 后无法重新注册 VSTO 加载项
- vb.net - 带有文本日志的路径保存文件
- javascript - 如何用另一个字母/特殊字符替换字符串中的所有字母?
- javascript - 单击后 Jquery 样式更改不断恢复
- c - 如何在 C 语言中按 ASCII 顺序对命令行参数进行排序
- uwp - 如何在给定 FrameworkElement 的情况下检索 CompositionEffect?
- node.js - pg-promise 助手:插入和多次更新中的可选字段