postgres如何使用INSERT和UPDATE重写merge语句

时间:2017-05-30 11:52:01

标签: sql postgresql sql-merge

我在Oracle中获得了Merge声明(迁移到EDB Postgres),但不幸的是,EDB postgres并不支持合并声明。

那么如何使用INSERT和UPDATE重写下面的merge语句。

BEGIN

        Merge into sds_dia_error_per_min_data using dual
        on (sde_date = in_date and sde_inst_name = in_inst_name
        and sde_interface_name = in_interface_name and sde_command_code = in_command_code and sde_result_code = in_result_code)
        when matched then
        update set
        sde_error_sent = sde_error_sent + in_error_sent,
        sde_error_received = sde_error_received + in_error_received
        WHEN NOT MATCHED THEN
        Insert (sde_date,sde_inst_name,sde_interface_name,sde_command_code,sde_result_code,sde_error_sent,
        sde_error_received)
        values
        (in_date,in_inst_name,in_interface_name,
        in_command_code,in_result_code,in_error_sent,
        in_error_received);

        out_status := 0 ;
COMMIT;

0 个答案:

没有答案