如何替换 PostgreSQL 中的变量

DUn*_*wn1 3 postgresql sqlplus psql

给定的 Oracle 查询通过替换变量将数据插入表中。我如何在 PostgreSQL 中实现相同的目标?

INSERT INTO control_threshold (
    threshold_id, group_name, description, sql, low_value, high_value)
VALUES(
    threshold_seq.nextval, '&2', '&1',  TRIM('&5' || '&6' || '&7' || '&8' || '&9'),
    trim('&3'), trim('&4'));
Run Code Online (Sandbox Code Playgroud)

Col*_*art 7

这些变量是 SQL*Plus 的一个特性。

psqlPostgreSQL 世界中的等价程序,也有变量。

\set variable 'value'
Run Code Online (Sandbox Code Playgroud)

insert into mytable(mycolumn)
values (:variable);
Run Code Online (Sandbox Code Playgroud)