【发布时间】:2019-02-04 19:54:06
【问题描述】:
编写一个将一些数据推送到 Postgres 数据库的 Node 应用程序。一列的数据类型是自定义复合类型的数组。
这是我要注入的内容:
'{(123, (12, "Some Description")),(null, (34, "Some Desc"))}'
复合类型有两个字段,其中第二个是另一个复合类型。我从 Postgres 得到的错误是给我的信息:
格式错误的数组字面量:“{(123, (12, "Some Description")),(null, (34, "Some Desc"))}"
详细说明:
意外的数组元素
该列被声明为数据类型:
my_custom_data_type[]
无法弄清楚这个异常。
【问题讨论】:
-
你试过
array[(123, (12, "Some Description")),(null, (34, "Some Desc"))]或array[(123, (12, "Some Description")),(null, (34, "Some Desc"))]::my_custom_data_type[]吗?数组构造函数语法 (array[...]) 通常比字符串形式 ('{...}') 更易于使用。 -
@muistooshort 效果很好,英勇的建议。如果您想将其作为答案提交,我会将其标记为正确。不得不想象其他人会在某个时候遇到这种情况。对于复合数据类型,您似乎必须使用您提到的
::my_custom_data_type[]方法才能在数组中使用它们。还有——谢谢一百万
标签: sql node.js postgresql