zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

PostgreSQL Oracle兼容性之 - psql prompt like Oracle SQL*Plus

OraclepostgresqlSQL Plus 兼容性 like prompt
2023-09-14 08:57:57 时间

Oracle的SQL*Plus客户端支持使用promote输入变量值,然后在脚本的其他位置使用该变量值。
例如大量的dbms脚本使用了这个用法, 如statspack输入起始值。
https://docs.oracle.com/cd/B19306_01/server.102/b14357/ch12032.htm
在PostgreSQL中,psql客户端也提供了类似的用法,例如:

postgres=# create table test(id int, info text);

CREATE TABLE

postgres=# insert into test select generate_series(1,100),test;

INSERT 0 100

提示输入ID的值,返回该ID对应的test的行。

vi test.sql

\prompt "please enter a id: " id

select * from test where id=:id;

dege.zzz@r10k04474- psql -h 127.0.0.1 -p 1922 -f ./test.sql

"please enter a id: "1

 id | info 

----+------

 1 | test

(1 row)

在psql命令行中执行

postgres=# \ir test.sql

"please enter a id: "1

 id | info 

----+------

 1 | test

(1 row)

 \i FILE execute commands from file

 \ir FILE as \i, but relative to location of current script

参考帮助文档

man psql

 \prompt [ text ] name

 Prompts the user to supply text, which is assigned to the variable name. An optional prompt string, text, can be specified. (For multiword prompts, surround the text with single quotes.)

 By default, \prompt uses the terminal for input and output. However, if the -f command line switch was used, \prompt uses standard input and standard output.

【.NET 6】使用EF Core 访问Oracle+Mysql+PostgreSQL并进行简单增改操作与性能比较 唠嗑一下。都在说去O或者开源,但是对于数据库选型来说,很多人却存在着误区。例如,去O,狭义上讲,是去Oracle数据库。但是从广义上来说,是去Oracle公司产品或者具有漂亮国垄断地位和需要商业授权的数据库产品。
关于PostgreSQL数据库兼容Oracle数据库闪回查询的实现方案 注:关于在PostgreSQL上面实现Oracle数据库的闪回功能(闪回查询 闪回表 闪回删除…)的这个想法已经有很长时间了,但是鉴于本人的能力 精力和身体条件 迟迟没有完成。期间也有很多的小伙伴跟我一起研究过这个功能,但是最终都因为各种各样的问题 没有做下去。Oracle数据库闪回功能跨越版本较大,功能也比较强大 在PostgreSQL数据库上实现,需要对数据库内核有很深入的理解 两大数据库不同的底层原理也终将影响各自的实现策略,PostgreSQL标记删除就地插入的特点和基于事务快照行可见性的特性是我们可以开发PostgreSQL闪回查询的大前提。本文主要介绍 实现闪回查询的 一种实现方案