hank=> \set name hank
hank=> \set time '2018-02-06 10:09:00'
hank=> select * from tb2 where c2=:'name' and c3>=:'time';
c1 | c2 | c3
----+------+----------------------------
1 | hank | 2018-02-06 10:08:00.787503
3.通过定义参数实现
设置一个session级别的参数,通过current_setting取值
hank=> set session "asasd.time" to "2018-02-06 10:09:00";
hank=> select * from tb2 where c3 >= current_setting('asasd.time')::timestamp;
c1 | c2 | c3
----+-------+----------------------------
4 | aaaaa | 2018-02-06 10:18:39.289523
(1 row)
补充:postgresql存储函数/存储过程用sql语句来给变量赋值
--定义变量
a numeric;
select sqla into a from table1 where b = '1' ; --这是sql语句赋值
sql1:= 'select a from table1 where b = ' '1' ' ';
execute sql1 into a; --这是执行存储函数赋值