简体   繁体   中英

How can I select a property from an object type column in postgresql

This is table:

Id    source_data           name

1.    {id: '1', value: 5}.  Ahmed
2.    {id: '3', value: 7}.  Aadi

I want to do this kind of query: Select Id, source_data.value, name From table

Assuming the data type of your source_data column is type json or jsonb :

SELECT
    id,
    source_data ->> 'value'
    name
FROM my_table

If it is of type text , you can cast it into json before:

SELECT
    id,
    source_data::json ->> 'value'
    name
FROM my_table

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM