How to get a json object as column in postgresql?

后端 未结 2 799
忘了有多久
忘了有多久 2021-01-01 17:39

I have these table on mu PostgreSQL 9.05:

Table: core Fields: name, description, data

data f

2条回答
  •  有刺的猬
    2021-01-01 17:52

    As of PostgreSQL 9.4 you can also use json_to_record.

    Builds an arbitrary record from a JSON object (see note below). As with all functions returning record, the caller must explicitly define the structure of the record with an AS clause.

    For example:

    select * from json_to_record('{"a":1,"b":[1,2,3],"c":"bar"}') as x(a int, b text, d text)
    

    Returns

     a |    b    | d
    ---+---------+---
     1 | [1,2,3] |
    

提交回复
热议问题