psql通过-v参数传递变量

--编写test_2.sql脚本

[postgres@localhost ~]$ cat test_2.sql
select * from test_2 where id=:v_id;
通过-v传递参数
[postgres@localhost ~]$ psql -v v_id=1 -f test_2.sql
id
----
1
(1 row)

 

posted @ 2021-10-13 21:42  罗论明  阅读(394)  评论(0编辑  收藏  举报