SQL standard UPSERT call

后端 未结 2 909
臣服心动
臣服心动 2021-01-12 06:40

I\'m looking for a standard SQL \"UPSERT\" statement. A one call for insert and update if exists.

I\'m looking for a working, efficient and cross platfo

2条回答
  •  半阙折子戏
    2021-01-12 07:01

    The syntax for doing an upsert in a single command varies by RDBMS.

    • MySQL
      INSERT…ON DUPLICATE KEY UPDATE
    • HSQLDB
      MERGE
    • Postgres
      INSERT…ON CONFLICT…

    See Wikipedia for more.

    If you want a cross platform solution, then you'll need to use multiple commands. First check for the existing row, then conditionally insert or update as appropriate.

提交回复
热议问题