我有一個名為 emp 的表,其中有一列名為 info 作為 jsonb 型別
現在我想從表中插入資料
所以看起來像這樣
{
"birth": {"date": "1980-04-28"},"Name": {"surname": "James","firstname": "Jacob"}
}
我發出 SQL
insert into emp(info)
select
row_to_json(x)::jsonb from
(select birth_date as date, lastname as surname, given_name as firstname FROM stg.employees) x;
但它回傳
{
"date": "1975-11-29T00:00:00",
"surname": "James",
"firstname":"Jaconb"
}
并不是
{
"birth": {"date": "1980-04-28"},
"Name": {"surname": "James","firstname": "Jacob"}
}
你能指出我正確的方向嗎?謝謝你
uj5u.com熱心網友回復:
insert into emp(info)
select
row_to_json(x)::jsonb from
(select jsonb_build_object('date', birth_date) as birth, jsonb_build_object('surname', lastname, 'firstname', given_name) as name FROM stg.employees) x;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/519949.html
