在PostgreSQL 9.5上合并 [英] Make MERGE on PostgreSQL 9.5

查看:133
本文介绍了在PostgreSQL 9.5上合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在PostgreSQL 9.5中进行合并,但出现以下错误:

I'm trying to do a MERGE in PostgreSQL 9.5 and I get the following error:

ERROR:  syntax error at or near "MERGE"
LINE 1: MERGE INTO TP_ESTADO_EQUIPOS AS EQ
        ^

********** Error **********

ERROR: syntax error at or near "MERGE"
SQL state: 42601
Character: 1

SQL

MERGE INTO TP_ESTADO_EQUIPOS AS EQ
USING (SELECT * FROM TEMP_TABLE_STATE_EQUIPMENT) AS VEQ
ON EQ.ESTADO_EQUIPOS_ID = VEQ.ESTADO_EQUIPO_ID
 WHEN MATCHED THEN (
 EQ.TIEMPO_INICIO=VEQ.TIEMPO_INICIO,
 EQ.TIEMPO_FIN=VEQ.TIEMPO_FIN,
 ...
 )
WHEN NOT MATCHED THEN
INSERT(Estado_Equipos_ID,
        Tiempo_Inicio,
        ...
        )
        VALUES(VEQ.ESTADO_EQUIPO_ID,
                VEQ.Tiempo_Inicio,
                ...);

我一直在阅读文档,可能必须使用 UPSERT ,但是我仍然不清楚这是否一定是错误。

I have been reading documentation, and I may have to use UPSERT, but it is still not clear to me if that is necessarily the error.

推荐答案

Postgres没有 MERGE 语句:

Postgres has no MERGE statement:

https://www.postgresql.org/docs/current/static/sql-commands.html

在冲突中使用插入代替:

https://www.postgresql.org/docs/current/static/sql-insert.html

MERGER 语句迈出了一步,但不一定一定是您期望的:

There are some movement towards MERGER statement, but it will not necessarily be smth that you expect:

https://wiki.postgresql.org/wiki/SQL_MERGE

这篇关于在PostgreSQL 9.5上合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆