【问题标题】:PostgreSQL use Select return in functionPostgreSQL 在函数中使用 Select 返回
【发布时间】: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


【解决方案1】:

我找到了解决方案。 查询必须像

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

感谢您的帮助

【讨论】:

    猜你喜欢
    • 2011-12-18
    • 1970-01-01
    • 2016-06-09
    • 1970-01-01
    • 1970-01-01
    • 2014-03-12
    • 1970-01-01
    • 2012-01-09
    • 2020-10-18
    相关资源
    最近更新 更多