Merge compare columns when null
Key words: merge compare columns
when we contact merge sql in ETL,
When we update some columns we should compare the value change or not.
We always write coalesce(columnname,valueifnull)<>coalesce(columnname,valueifnull)
But we should take care of the valueifnull, the value should not exist in tables and the data type
Should be right. Two points need to satisfy the requirements.
If you want to use sql to generate the sql automatically, you should know the column type for every column,
We can get this from database's meta data table, but we also need set the value if the column is null, this part
Will need a long case when , if not , we should have a configuration table to store this.
Another solution is :
Oracle:
Merge into target tar using (select * from source) as src
On tar.colx=src.colx…
When matched Update set col=src.col … where tar.col!=src.col or ( tar.col is null and src.col is not null) or (tar.col is not null and src.col is null)
It is long , if we execute it dynamically , the string may long exceed varchar2(4000);
Tar.col!=src.col (when the both columns are valid and not null)
Now, I think another expression to stand for not equal.
Not ( tar.col is null and src.col is null)
Sqlserver:
Merge into target tar using (select * from source) as src
On tar.colx=src.colx…
When matched and
(
tar.col<>src.col
Or not (tar.col is null and src.col is null)
Or ….
)
Update set coly=src.coly
…
You will notice that, there are some differences in merge implementation for oracle and sqlserver.
Slqserver is more powerful on this.
It support when matched and conditions but oracle not support this , but you can add the filter at where clause.
Just update what you want to update.
Another thing is sqlserver can judge the not matched case is caused by target table or source table.
When not matched by target table, insert data from source table.
When not matched by source talbe, just delete or do other actions.
On clause in merge is also need take care.
On tar.col=src.col and (tar.col is null and src.col is null)
Maybe is useful for your query.
Merge compare columns when null的更多相关文章
- Collectors.toMap不允许Null Value导致NPE
背景 线上某任务出现报警,报错日志如下: java.lang.NullPointerException: null at java.util.HashMap.merge(HashMap.java:12 ...
- Git 集成 Araxis Merge 作为比较和合并GUI工具的配置 参考自https://www.kancloud.cn/leviio/git/369125
Git 集成 Araxis Merge Win10下修改git全部配置文件方法Git 集成 Araxis Merge 作为比较和合并GUI工具的配置 那global对应的 ,gitconfig文件在哪 ...
- SQL基础笔记
Codecademy中Learn SQL, SQL: Table Transformaton和SQL: Analyzing Business Metrics三门课程的笔记,以及补充的附加笔记. Cod ...
- mysql的TABLE_SCHEMA的sql和information_schema表, MySQL管理一些基础SQL语句, Changes in MySQL 5.7.2
3.查看库表的最后mysql修改时间, 如果第一次新建的表可能还没有update_time,所以这里用了ifnull,当update_time为null时用create_time替代 select T ...
- Known BREAKING CHANGES from NH3.3.3.GA to 4.0.0
Build 4.0.0.Alpha1 ============================= ** Known BREAKING CHANGES from NH3.3.3.GA to 4.0. ...
- .NET导入导出Excel方法总结
最近,应项目的需求,需要实现Excel的导入导出功能,对于Web架构的Excel导入导出功能,比较传统的实现方式是: 1)导入Excel:将Excel文件上传到服务器的某一文件夹下,然后在服务端完成E ...
- PostgreSQL index types and index bloating
warehouse_db=# create table item (item_id integer not null,item_name text,item_price numeric,item_da ...
- yii 笔记
Yii1.1: $_GET 可以表示为 Yii::app()->request->getQuery() $_POST 可以表示为 Yii::app()->request->po ...
- Mapper XML Files详解
扫扫关注"茶爸爸"微信公众号 坚持最初的执着,从不曾有半点懈怠,为优秀而努力,为证明自己而活. Mapper XML Files The true power of MyBatis ...
随机推荐
- 重新想象 Windows 8.1 Store Apps (74) - 新增控件: Flyout, MenuFlyout, SettingsFlyout
[源码下载] 重新想象 Windows 8.1 Store Apps (74) - 新增控件: Flyout, MenuFlyout, SettingsFlyout 作者:webabcd 介绍重新想象 ...
- 最全面的jdbcUtils,总有一种适合你
附加jar包,TxQueryRunner.java文件,dbconfig.properties配置文件(点击链接下载): http://files.cnblogs.com/files/xiaoming ...
- .NET Framework 4.0之Tuple(元组)
Tuple,是函数式编程的概念之一,早见于Elang.F#等动态语言.Tuple类型像一个口袋,在出门前可以把所需的任何东西一股脑地放在里面.您可以将钥匙.驾驶证.便笺簿和钢笔放在口袋里,您的口袋是存 ...
- 浅谈React受控与非受控组件
背景 React内部分别使用了props, state来区分组件的属性和状态.props用来定义组件外部传进来的属性, 属于那种经过外部定义之后, 组件内部就无法改变.而state维持组件内部的状态更 ...
- 设置ArcGIS的外观改回到出厂
在一般的软件中,都可以在工具-选项中打开相关设置将应用程序的外观改回到出厂.但ArcGIS好像没有,但查帮助文档原来是这样: 配置的更改保存在模板文档中(例如,ArcMap 将其更改保存在 Norma ...
- SharePoint 服务器端对象模型 之 使用LINQ进行数据访问操作(Part 2)
(四)使用LINQ进行列表查询 在生成实体类之后,就可以利用LINQ的强大查询能力进行SharePoint列表数据的查询了.在传统SharePoint对象模型编程中,需要首先获取网站对象,再进行其他操 ...
- android XMl 解析神奇xstream 四: 将复杂的xml文件解析为对象
前言:对xstream不理解的请看: android XMl 解析神奇xstream 一: 解析android项目中 asset 文件夹 下的 aa.xml 文件 android XMl 解析神奇xs ...
- Android DiskLruCache 硬盘缓存
概述 记得在很早之前,我有写过一篇文章Android高效加载大图.多图解决方案,有效避免程序OOM,这篇文章是翻译自Android Doc的,其中防止多图OOM的核心解决思路就是使用LruCache技 ...
- Ubuntu14.04下安装Hadoop2.5.1 (单机模式)
本文地址:http://www.cnblogs.com/archimedes/p/hadoop-standalone-mode.html,转载请注明源地址. 欢迎关注我的个人博客:www.wuyudo ...
- Web应用程序系统的多用户权限控制设计及实现-数据库设计【2】
搭建一个Web权限配置的系统,需要以下五张数据表:人员表,分组表,页面表,目录表,操作权限表.各张数据表中用到的id均为自增1的标识,每张数据表的定义如下: 1.1人员表(operatorinfo)