在PostgreSQL中更新退货单 [英] Update Returning Order by in postgresql

查看:92
本文介绍了在PostgreSQL中更新退货单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查询,用于更新表中的行。我希望查询更新行并返回受影响的行。

I have a query updating rows in a table. I want the query to update the rows and return the rows affected.

当前我有

UPDATE employees SET name = 'John' RETURNING employees.*;

这很好。但是,如果我想按指定顺序返回受影响的行,该怎么办?

This works fine. But what if I want to return the rows affected in a specified order. Something like

UPDATE employees SET name = 'John' RETURNING employees.* ORDER BY name ASC;

这不起作用。

推荐答案

这可以通过使用修改CTE(公用表表达式)的数据来完成:

This can be done using a data modifying CTE (common table expression):

with updated as (
    UPDATE employees 
        SET name = 'John' 
    RETURNING *
)
select *
from updated
ORDER BY empname ASC;

这篇关于在PostgreSQL中更新退货单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆