0

在搜索站点(和其他......)之后,我找不到允许我将“返回”值存储到表、CTE 等的插入命令的示例。这就是我想做的:

WITH insert_rows AS (
  INSERT INTO employers (column1, column2, insert_date)
  SELECT distinct tc.column1, 'any text', now()
  FROM _tmp_employer_updates tc
  LEFT JOIN employers e ON e.column1 = tc.column1
  WHERE e.column1 IS NULL   -- Only insert non-existing employer names
  RETURNING employer.row_uuid, employer.column1, employer.column2;
  )
SELECT * FROM insert_rows; -- table of returning values

无论如何,是否有一个插入命令来使用 CTE 将其“返回”值存储到表中?当我尝试上面的示例时,我得到:

错误:“INSERT”第 1 行或附近的语法错误:... _tmp_inserted_employers AS WITH insert_rows AS (INSERT INT...

提前致谢...

4

1 回答 1

1

删除;之后,删除列之前的returning ...别名(或将其更改为)。否则,您的查询看起来不错。employerreturningemployers

这是关于sql fiddle的示例。

于 2013-10-29T16:22:36.653 回答