Имейте массив, как показано ниже, его необходимо сохранить в столбце JSONB:
[{"FoodType":"veg","pref":"High"}
,{"FoodType":"sea food","pref":"Medium"}
,{"FoodType":"Chicken","pref":"Low"}]
Я просто передаю объект req.body (из Express) для вставки в БД.
db.one('insert into foodies(FoodieName, FoodPref,country,languagePref)' +
'values(${FoodieName}, $[FoodPref], ${country} ,${languagePref}) RETURNING FoodieId',req.body)
**БД PG через библиотеку pg-promise выдает ошибку:
{ [error: column "foodpref" is of type jsonb but expression is of type text[]]
name: 'error',
length: 196,
severity: 'ERROR',
code: '42804',
detail: undefined,
hint: 'You will need to rewrite or cast the expression.',
position: '123',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_target.c',
line: '529',
routine: 'transformAssignedExpr' }
POST /api/member 500 638.510 ms - 57
я думаю, что его драйвер выдает массив cos: функция (arr) в formatting.js [в pg-promise lib] возвращает строку, и postgres не может ее переварить. Если массив вложен в какой-либо объект, он работает гладко, например.
"MyPref" : {Same Object array as above}
Здесь MyPref без проблем проходит через столбец «FoodPref».
pgp.as.format
, а не то, что вы передаете в метод запроса. - person vitaly-t   schedule 20.11.2016pgp.as.format(query, values)
, он возвращает отформатированную строку запроса. - person vitaly-t   schedule 20.11.2016