postgres 从修改行返回数据
来源:互联网 发布:网络短剧排名 编辑:程序博客网 时间:2024/06/06 19:20
Returning Data From Modified Rows
Sometimes it is useful to obtain data from modified rows while they are being manipulated. The INSERT, UPDATE, and DELETE commands all have an optional RETURNING clause that supports this. Use of RETURNING avoids performing an extra database query to collect the data, and is especially valuable when it would otherwise be difficult to identify the modified rows reliably.
The allowed contents of a RETURNING clause are the same as a SELECT command’s output list (see Section 7.3). It can contain column names of the command’s target table, or value expressions using those columns. A common shorthand is RETURNING *, which selects all columns of the target table in order.
In an INSERT, the data available to RETURNING is the row as it was inserted. This is not so useful in trivial inserts, since it would just repeat the data provided by the client. But it can be very handy when relying on computed default values. For example, when using a serial column to provide unique identifiers, RETURNING can return the ID assigned to a new row:
CREATE TABLE users (firstname text, lastname text, id serial primary key);INSERT INTO users (firstname, lastname) VALUES ('Joe', 'Cool') RETURNING id;
The RETURNING clause is also very useful with INSERT … SELECT.
In an UPDATE, the data available to RETURNING is the new content of the modified row. For example:
UPDATE products SET price = price * 1.10 WHERE price <= 99.99 RETURNING name, price AS new_price;
In a DELETE, the data available to RETURNING is the content of the deleted row. For example:
DELETE FROM products WHERE obsoletion_date = 'today' RETURNING *;
- postgres 从修改行返回数据
- 从csv文件导入数据到postgres
- PostgreSQL 数据迁移 (从Mysql到Postgres)
- postgres直接查看function返回的游标数据
- 修改ambari postgres-embedded数据库源数据,删除服务
- 数据修改之返回修改的数据
- 修改postgres编码
- 修改postgres时区
- postgres修改归档模式
- postgres 修改视图
- 从DataSet 返回XML 数据
- Android 从Activity返回数据
- Java 从线程返回数据
- Excel 数据导入 Postgres
- postgres数据恢复(windows)
- postgres拷贝指定数据
- postgres数据导入导出
- 从SERVER返回数据中提取数据
- 图像处理之基于OTSU阈值二值化
- wchar、tchar、L等宽窄字符的含义与转换
- Java多态中重载方法参数分别为父类和子类时的疑惑
- kerberos管理开发总结
- 浅谈画笔Xfermode
- postgres 从修改行返回数据
- OkHttp拦截器POST添加公共参数
- 11.21第14节课
- CATIA小插件发布步骤及解析
- Android Local Manifests机制
- 微信禁用右上角的分享按钮,WeixinJSBridge API以及隐藏分享的子按钮等菜单项
- 从DICOM开始入门医学图像处理-1-开发工具
- Resources.class.getResourceAsStream 获取配置的方法
- 大话设计模式读书笔记之策略模式