Oracle查询到PostgreSQL的转换

时间:2018-11-11 14:08:47

标签: sql database oracle postgresql database-migration

您能帮助一些将Oracle查询转换为PostgreSQL查询吗,它存在吗?

我有一个Oracle查询,我想将其用于postgreSQL,您能帮我吗?

merge into TABLE_NAME using dual on 
(ID='CF9EB9FE6F6D4CC9B75EC0CD420421B91541944569' and ANOTHER_ID='E198D55909D94895AF747ED7E032AC58') 
when matched then update set USER='USERNAME' 
when not matched then insert values('EEA2620A4A0F31CE05E69B','CFB75EC0CD41B91541944569','E198D55909D94895AF747ED7E032AC58','USERNAME',null) 

1 个答案:

答案 0 :(得分:1)

您使用insert . . . on conflict在Postgres中进行upsert

insert into table_name (?, id, anotherid, ?, ?)   -- put in the column names
    values('EEA2620A4A0F31CE05E69B', 
           'CFB75EC0CD41B91541944569', 
           'E198D55909D94895AF747ED7E032AC58',
           'USERNAME', null
          )
    on conflict (id, anotherid)
    do update set USER = 'USERNAME';

您想要对(id, anotherid)施加唯一约束,以便识别冲突:

alter table table_name add constraint unq_tablename_id_anotherid unique (id, anotherid);

需要在会导致冲突的列上定义唯一约束。