小编Faw*_*awn的帖子

按索引删除数组元素

是否可以通过索引删除 Postgres 数组元素?(使用 Postgres 9.3。)

我在文档(http://www.postgresql.org/docs/9.3/static/functions-array.html)中没有看到任何相关内容,但也许我还缺少其他功能?

postgresql array

6
推荐指数
1
解决办法
1万
查看次数

Postgres 9.3:除了其他选择标准之外,如何更新具有时间戳最大值的行?

我想允许用户取消定期订阅。考虑到我拥有的其他基础设施,最简单的方法是recurring为用户的最新约会(日期)设置字段 = 0。所以我只需要recurring在匹配特定用户的最新约会的行中更新字段的值。

这是我尝试过的:

UPDATE appointments SET recurring = 0 WHERE id = 433 AND time = max(time);


ERROR:  aggregate functions are not allowed in WHERE
LINE 1: ...ments set recurring = 0 where id = 433 and time = MAX(time);
Run Code Online (Sandbox Code Playgroud)

 UPDATE appointments SET recurring = 0 WHERE id = 433 AND time = SELECT MAX(time) FROM appointments WHERE id = 433;
Run Code Online (Sandbox Code Playgroud)

这是约会表的相关部分:

                                           Table "public.appointments"
      Column      |            Type             |                           Modifiers
------------------+-----------------------------+----------------------------------------------------------------
 id               | integer                     | …
Run Code Online (Sandbox Code Playgroud)

postgresql

4
推荐指数
1
解决办法
3531
查看次数

标签 统计

postgresql ×2

array ×1