【发布时间】:2016-10-28 16:34:29
【问题描述】:
我正在尝试运行类似的查询
select id from table where id = pseudo_encrypt(select last_value from id_seq)
..
select last_value from id_seq
返回 5,这是正确的结果。我的问题是如何将其用作函数参数
故事是我将表的 id 存储为 id_seq 的加密值。
所以我需要得到 id 与加密匹配的结果。
select last_value from id_seq
我想我需要写一个函数,但我不擅长 Postgresql。
【问题讨论】:
-
您应该使用
nextval()和currval()而不是直接查询序列。 -
select * from table where id = pseudo_encrypt(currval('id_seq')) 我在上面尝试过,但它返回 ERROR: currval of sequence "id_seq" is not yet defined in this session SQL state: 55000
标签: postgresql postgresql-9.4 sql-function