PostgreSQL-从列值设置JSONB属性

PostgreSQL-从列值设置JSONB属性,postgresql,psql,Postgresql,Psql,我有一个数字列total\u price,我想将其移动到名为price\u detail的jsonb属性。例如,如果total_price值为1000,则预期的price_detail值为{“totalPrice”:1000} 我尝试过使用jsonb_集,但结果是空对象{} UPDATE public.orders SET price_detail = jsonb_set('{}' , '{}' , jsonb_build

我有一个数字列
total\u price
,我想将其移动到名为
price\u detail
的jsonb属性。例如,如果
total_price
值为1000,则预期的
price_detail
值为
{“totalPrice”:1000}

我尝试过使用
jsonb_集
,但结果是空对象
{}

UPDATE public.orders SET price_detail =
       jsonb_set('{}'
               , '{}'
               , jsonb_build_object('totalPrice', total_price::numeric)) 
如果我设定路径

UPDATE public.orders SET price_detail =
       jsonb_set('{}'
               , '{totalPrice}'
               , jsonb_build_object('totalPrice', total_price::numeric)) 
结果是
{“totalPrice”:{“totalPrice”:1000}
,这是意外的


如何正确设置
totalPrice
属性?

您不需要
JSONB\u集
,只需使用
JSONB\u BUILD\u对象

UPDATE orders 
SET price_detail = JSONB_BUILD_OBJECT('totalPrice', total_price::numeric)