postgresql update from
1,update from 关联表的更新
update table a set name=b.name from table B b where a.id=b.id;
update test set info=tmp.info from (values (1,'new1'),(2,'new2'),(6,'new6')) as tmp (id,info) where test.id=tmp.id;
2 update from
update TABLEA a
set update_time=now,
name=case when b.name is not null then d.name else a.name end,
age=case when b.age is not null then d.age else a.age end
from TABELEB b where a.id=b.id;
3.实际应用举例:
update dp1.m_task mt set update_date=now() , is_delegated=case when d.is_delegated is not null then d.is_delegated else mt.is_delegated end , priority=case when d.priority is not null then d.priority else mt.priority end , status=case when d.status is not null then d.status else mt.status end, task_group_id=case when d.task_group_id is not null then d.task_group_id else mt.task_group_id end , task_name=case when d.task_name is not null then d.task_name else mt.task_name end , team_id=case when d.team_id is not null then d.team_id else mt.team_id end
from (
select 100 as client_id,
is_delegated::integer,priority::integer,status::smallint,task_code::character varying,task_group_id::integer,task_name::character varying,team_id::integer
from (
select rowindex,is_delegated,priority,status,task_code,task_group_id,task_name,team_id
from ext.crosstab (
'
select rowindex,column_name,column_value
from field_fixed_detail_table a
',
'
select column_name from fixed_column_table
'
)
as ct ( rowindex integer,is_delegated varchar,priority varchar,status varchar,task_code varchar,task_group_id varchar,task_integrate_code varchar,task_name varchar,team_id varchar)
) as fixed
) as d
where mt.task_code=d.task_code;
postgresql update from的更多相关文章
- PostgreSQL - update语句怎么关联多个表
问题 对于select语句,我们可以通过join/outer join来关联多个表:但是对于update语句,是不能直接通过join/outer join来关联多表数据的,这里仅针对PostgreSQ ...
- PostgreSQL update set from 两表联合更新,注意与其它数据库更新语法有差别
最近用PostgreSql数据库进行表关联更新时,发现与之前用的Sql Server 和My Sql语法有很大差别,稍微不注意,很容易出错. PostgreSql表更新时,两个表只允许一个表起别名,一 ...
- what a fuck postgre update sql
================= what a fuck postgre update sql ================= UPDATE temp_group_temp set group_ ...
- postgresql删除属性
PostgreSQL update and delete property from JSONB column up vote 2 down vote favorite From this artic ...
- Citus 分布式 PostgreSQL 集群 - SQL Reference(摄取、修改数据 DML)
插入数据 要将数据插入分布式表,您可以使用标准 PostgreSQL INSERT 命令.例如,我们从 Github 存档数据集中随机选择两行. INSERT http://www.postgresq ...
- Spring Authorization Server(AS)从 Mysql 中读取客户端、用户
Spring AS 持久化 jdk version: 17 spring boot version: 2.7.0 spring authorization server:0.3.0 mysql ver ...
- PG cannot execute UPDATE in a read-only transaction | How to add column if not exists on PostgreSQL
PG cannot execute UPDATE in a read-only transaction出现这种情况时,说明SQL语句可能是运行在一个PG集群中的非master节点上.查看data/pg ...
- PostgreSQL在Update时使用Substring函数截取字符串并且加上CASE WHEN THEN条件判断
--更新 UPDATE wp_order_detail SET layout_type = ( SELECT CASE THEN ) ELSE '' END FROM wp_catalog_size ...
- ASP.NET MVC 使用 Petapoco 微型ORM框架+NpgSql驱动连接 PostgreSQL数据库
前段时间在园子里看到了小蝶惊鸿 发布的有关绿色版的Linux.NET——“Jws.Mono”.由于我对.Net程序跑在Linux上非常感兴趣,自己也看了一些有关mono的资料,但是一直没有时间抽出时间 ...
随机推荐
- UVA 437 The Tower of Babylon巴比伦塔
题意:有n(n≤30)种立方体,每种有无穷多个.要求选一些立方体摞成一根尽量高的柱子(可以自行选择哪一条边作为高),使得每个立方体的底面长宽分别严格小于它下方立方体的底面长宽. 评测地址:http:/ ...
- 大括号对struct进行初始化
1 partial initialization 即所谓的部分初始化. 这个时候,无论该struct变量是static的还是automic的,未显式初始化的成员都会被初始化为默认值.
- Koa2学习(一)环境搭建
Koa2学习(一)环境搭建 koa2脚手架 koa2服务安装 koa2-generator目录结构 什么是 Koa2 koa 是由 Express 原班人马打造的,致力于成为一个更小.更富有表现力.更 ...
- QmlWinExtras
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/zhengtianzuo06/article/details/78404961QtWinExtras是 ...
- YTU 2555: 老大的烦恼
2555: 老大的烦恼 时间限制: 1 Sec 内存限制: 128 MB 提交: 176 解决: 47 题目描述 万恶的小黑,布置了一道题给老大做:给你一个n位的数,现在要求 你随意删除m位后,任 ...
- android NDK 使用(多个)静态库生成动态库
android NDK 使用(多个)静态库生成动态库. 1.编写Android.mk文件:如下两种方式都可以,用于NDK编译工具生成的两个.a文件来生成最终的libtwolib-second.so动态 ...
- Avoiding memory leaks
Android applications are, at least on the T-Mobile G1, limited to 16 MB of heap. It's both a lot of ...
- ValueError: Some of types cannot be determined by the first 100 rows, please try again with sampling
ValueError: Some of types cannot be determined by the first 100 rows, please try again with sampling ...
- [Codeforces Round #461 (Div2)] 题解
[比赛链接] http://codeforces.com/contest/922 [题解] Problem A. Cloning Toys [算法] 当y = 0 , 不可以 当 ...
- AutoIT: 返回文件目录下所有的文件名,包括子文件
_filelist("D:\Snagit 10") Func _filelist($searchdir) ;;;函数名(形参) $search = FileFindFirstFil ...