我有一个对象如下。我想迭代insert中的每个用户,并将它们插入到我的数据库中。我被困在如何到达内部物体。我有下面这样的代码,我被困在如何进一步进入obejct,它只得到 insert
, delete
以及 update
. 我用的是postgresql。
我懂了 ->> int Get JSON array element as text '[1,2,3]'::json->>2
在文档中,但不知道如何合并到我的代码中
DECLARE
_key text;
_value text;
BEGIN
FOR _key, _value IN
SELECT * FROM jsonb_each_text($1)
LOOP
RAISE NOTICE '%: %', _key, _value;
END LOOP;
RETURN input;
END
{
insert: {
jsmith:
{
name: 'John Smith',
mail: 'JSmith@smith.com',
jobTitle: 'Lead',
hasImage: true,
teamId: '35'
},
lmark:
{
name: 'Laurendy Mark',
mail: 'LMark@mark.com',
jobTitle: 'System Admin',
hasImage: true,
teamId: '40'
}
},
delete: {
lbeth
{
name: 'Lisa Beth',
mail: 'LBeth@smith.com',
jobTitle: 'Assistant Director',
hasImage: true,
teamId: '40',
uid: '200'
}
},
update: {}
}
1条答案
按热度按时间ttisahbt1#
对此,您并不真正需要pl/pgsql函数。这可以使用数据修改cte来完成
在线示例