我想使用sailsjs
的水线 ORM 在postgresql表的一列中插入字符串数组。
我试图像这样制作模型Users.js
:
interest:{
type: 'string',
required: false,
columnType: 'array'
}
插入查询如下:
Users.create({ interest : ['programming'] });
postgre表中兴趣列的数据类型为character varying[]
。
当我尝试使用此设置执行插入操作时,会引发错误:
Specified value (a array: [ 'programming' ]) doesn't match the expected type: 'string'
如何在postgresql表中插入数组,模型应如何显示?任何帮助将不胜感激。
答案 0 :(得分:0)
我在整个项目中都使用了PG数组,并且在使用type: 'ref'
并在columnType
中指定postgres数组类型时从未遇到任何问题。类似于以下内容:
things: {
type: 'ref',
columnType: 'text[]',
defaultsTo: null, // or defaultsTo: []
description: 'An array of stringy-things',
},
PG数组类型文档:https://www.postgresql.org/docs/9.1/arrays.html,但基本上您可能希望对列类型使用<TYPE>[]
,例如integer[]
等