PostgreSQL使用Select函数

时间:2016-10-28 16:34:29

标签: postgresql postgresql-9.4 sql-function

我正在尝试运行像

这样的查询
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

此查询返回 enter image description here

我需要的结果是enter image description here

我想我需要写一个函数,但我不擅长Postgresql。

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。 查询必须类似于

select * from table where id = pseudo_encrypt(currval('id_seq'::regclass))

感谢您的帮助