代码之家  ›  专栏  ›  技术社区  ›  Dan Tanner

从PostgreSQL表中弹出一行

  •  0
  • Dan Tanner  · 技术社区  · 7 年前

    什么是Redis的等价物 LPOP PostgresSQL中的命令?

    things 只有一列 thing

    thing
    ----
    a
    b
    

    以原子方式删除并返回表中的行的正确命令是什么?使用上面的示例,我希望它返回一行('a'),并将其作为事务/锁的一部分删除。

    0 回复  |  直到 7 年前
        1
  •  3
  •   a_horse_with_no_name    7 年前

    data modifying common table expression

    with deleted as (
      delete from things
      where thing = 'a'
      returning *
    )
    select *
    from deleted;