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 ...
随机推荐
- linux下基本命令总结
基本linux命令的使用方法及实例,总结一些常用的命令: 一.创建文件和目录命令:mkdir touch(vim用得较多) 1)mdkir创建一个目录,创建多目录格式 mkdir –p a/{a,b ...
- xshell下载文件到本地/上传文件到服务器
xshell很好用,然后有时候想在windows和linux上传或下载某个文件,其实有个很简单的方法就是rz,sz首先你的Ubuntu需要安装rz.sz(如果没有安装请执行以下命令,安装完的请跳过.其 ...
- Servlet获得Http请求,GET/POST
Servlet获得Http请求 Http请求信息格式 请求行(方法提交方式,URI,Http协议版本) GET方式提交:URI会包含查询字符串 POST方式提交:URI不会包含查询字符串 请求头 Ho ...
- mysql init-file参数中语句限制
mysql 启动选项中的init-file文件的内容目测只能是dml语句,不能包含ddl,否则执行就会报错,但不影响启动本身..太扯了..
- Android:TextView 自动滚动(跑马灯) (转)
Android:TextView 自动滚动(跑马灯) TextView实现文字滚动需要以下几个要点: 1.文字长度长于可显示范围:android:singleLine="true ...
- [Azure] Notification Hubs注册模式
[Azure] Notification Hubs注册模式 关于Azure Notification Hubs的注册模式,可以参考下列连结的文件内容. Notification Hubs Featur ...
- 我为什么要做富文本编辑器【wangEditor5个月总结】
请访问wangEditor官网:www.wangEditor.com ----------------------------------------------------------------- ...
- [js开源组件开发]js轮播图片支持手机滑动切换
js轮播图片支持手机滑动切换 carousel-image 轮播图片,支持触摸滑动. 例子见DEMO http://www.lovewebgames.com/jsmodule/carousel-ima ...
- 趣味问题:画图(c++实现)
描述:在一个定义了直角坐标系的纸上,画一个(x1,y1)到(x2,y2)的矩形指将横坐标范围从x1到x2,纵坐标范围从y1到y2之间的区域涂上颜色.下图给出了一个画了两个矩形的例子.第一个矩形是(1, ...
- Math对象常用方法汇总
前几天翻阅<JavaScript权威指南>,看到了Math对象,于是汇总了一下. Math对象不同于其他的对象,它可以说是一个公共数学类,里面有很多数学方法,用于各种数学运算,但是Math ...