How to get only the jsonb of specific keys from postgres?

后端 未结 5 542
忘掉有多难
忘掉有多难 2021-02-06 01:10

I\'m aware that you can remove keys from a jsonb in postgres using something like this

select \'{\"a\": 1, \"b\": 2, \"c\":3}\'::jsonb -\'a\';
 ?column?
--------         


        
5条回答
  •  不要未来只要你来
    2021-02-06 01:34

    You can get just the value like so:

     select '{"a": 1, "b": 2}'::jsonb-> 'a';
    

    If you must, you can transform that back into jsonb manually, or perhaps go through an array, hstore or other intermediate type. Here's the "manual" way

     select ('{ "a": '||('{"a": 1, "b": 2}'::jsonb->'a')::text||'}')::jsonb
    

提交回复
热议问题