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的更多相关文章

  1. Collectors.toMap不允许Null Value导致NPE

    背景 线上某任务出现报警,报错日志如下: java.lang.NullPointerException: null at java.util.HashMap.merge(HashMap.java:12 ...

  2. Git 集成 Araxis Merge 作为比较和合并GUI工具的配置 参考自https://www.kancloud.cn/leviio/git/369125

    Git 集成 Araxis Merge Win10下修改git全部配置文件方法Git 集成 Araxis Merge 作为比较和合并GUI工具的配置 那global对应的 ,gitconfig文件在哪 ...

  3. SQL基础笔记

    Codecademy中Learn SQL, SQL: Table Transformaton和SQL: Analyzing Business Metrics三门课程的笔记,以及补充的附加笔记. Cod ...

  4. 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 ...

  5. 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. ...

  6. .NET导入导出Excel方法总结

    最近,应项目的需求,需要实现Excel的导入导出功能,对于Web架构的Excel导入导出功能,比较传统的实现方式是: 1)导入Excel:将Excel文件上传到服务器的某一文件夹下,然后在服务端完成E ...

  7. PostgreSQL index types and index bloating

    warehouse_db=# create table item (item_id integer not null,item_name text,item_price numeric,item_da ...

  8. yii 笔记

    Yii1.1: $_GET 可以表示为 Yii::app()->request->getQuery() $_POST 可以表示为 Yii::app()->request->po ...

  9. Mapper XML Files详解

    扫扫关注"茶爸爸"微信公众号 坚持最初的执着,从不曾有半点懈怠,为优秀而努力,为证明自己而活. Mapper XML Files The true power of MyBatis ...

随机推荐

  1. Dubbo初探

    Dubbo是什么? 1.阿里巴巴开源项目.2.Dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案. ps: SOA(面相服务的体系结构) RPC( ...

  2. Webform(简单控件、复合控件)

    一.简单控件: 1.label控件 <asp:Label ID="Label1" runat="server" Text="账 号:" ...

  3. Linux 学习手记(3):Linux基本的文件管理操作

    复制文件和目录 在Linux中使用命令cp来复制文件或者目录,使用方式: cp 源文件(文件夹) 目标文件(文件夹) cp命令常用参数: -r 递归复制整个目录 -v 显示详细信息 移动.重命名一个文 ...

  4. cl_gui_cfw=>flush

       用法一:      REFRESH_TABLE_DISPLAY虽然刷新的界面,但是SAP GUI并不是实时更新,而是将更新的结果放在缓存中,手动调用CL_GUI_CFW=>FLUSH才能触 ...

  5. 在SharePoint中无代码开发InfoPath应用: 一个测试Web Service的工具

    这是这个系列的第一篇,介绍一个小工具,主要是用在Web Service测试的. 因为为了用一点高级的东西,就免不了和web service打交道. 你可以使用按照KB819267来修改web.conf ...

  6. 2015年第4本(英文第3本):Godfather教父

    2015年的第4本书,第3本英文书. 书名:Godfather ,中文书名<教父> 作者: Mario Puzo 单词数:17万 词汇量:1万 首万词不重复词数:2200(这个我不太相信) ...

  7. [android] SQLite 数据库的升级 和 降级

    public class SqliteHelp extends SQLiteOpenHelper { /* * context:创建数据库所需的 上下文对象 * name: 数据库名字 * facto ...

  8. win-tc图形库编程

    本文地址:http://www.cnblogs.com/archimedes/p/win-tc-graphics-use.html,转载请注明源地址. 由于最近接到一个紧急任务,需要实现一个程序,显示 ...

  9. OC知识梳理-NSArray与NSMutableArray相关知识

    知识普及: 1.数组中的元素在系统中都会有其默认对应的下标,下标是一个整形的数字,默认从0开始. 例:NSArray *arr3 = @["345","234" ...

  10. IOS 网络浅析-(三 NSURLConnection代理)

    对于现在的iOS开发,用法简单,最古老最经典最直接的NSURLConnection的作用不是很大,但是作为一名ios开发者,我们应该拥有一颗热爱学习的心,下面通过代码的实现简单介绍一下NSURLCon ...