从JSONB插入uuid会导致错误:uuid的输入语法无效:

时间:2018-10-19 19:57:12

标签: arrays json postgresql syntax-error postgres-9.6

我正在尝试从jsonb数组中插入一系列值到postgres中。但是,出现错误error: invalid input syntax for uuid:

我的数据看起来像这样

[
  {
    code: "dwfwradsa",
    purpose: "description",
    id: uuid (real uuid, this is just a placeholder)
  },
  {repeat},
  {repeat}
]

我功能的相关部分如下。 @codes是传递给函数的参数。

  INSERT INTO
    "codes" (
      "code",
      "purpose",
      "id"
    )
  SELECT
    codes->>'code',
    codes->>'purpose',
    codes->>'id'::UUID -- this is a foreign key from another table
  FROM jsonb_array_elements("@codes") codes
  ON CONFLICT ON CONSTRAINT unique_code DO NOTHING;

甚至铸造似乎也无法解决问题。

如果我不进行投射,则会收到此错误error: column "fulfillment_center" is of type uuid but expression is of type text

0 个答案:

没有答案