postgresqlHow do I query data stored in PostgreSQL's JSONB data type?
PostgreSQL's JSONB data type is a binary representation of JSON that allows for fast read/write access and indexing. To query data stored in JSONB, the ->
and ->>
operators can be used.
The ->
operator will return a JSON object, while the ->>
operator will return text.
For example:
SELECT
my_json->'name' AS name,
my_json->'age' AS age
FROM
my_table;
This will return the name
and age
fields from the my_json
JSONB column in my_table
.
The following list explains the parts of the example query:
SELECT
- begins the query and specifies which columns to returnmy_json->'name'
- uses the->
operator to return thename
field from themy_json
column as a JSON objectAS name
- assigns the result of the->
operator to thename
columnmy_json->'age'
- uses the->
operator to return theage
field from themy_json
column as a JSON objectAS age
- assigns the result of the->
operator to theage
columnFROM my_table
- specifies the table to query
Helpful links
More of Postgresql
- How can Zalando use PostgreSQL to improve its software development?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How can I use PostgreSQL with YAML?
- How can I use PostgreSQL and ZFS snapshots together?
- How can I use PostgreSQL XML functions to manipulate XML data?
- How do I parse XML data using PostgreSQL?
- How can I use PostgreSQL and Node.js together to develop a software application?
- How do I use PostgreSQL aggregate functions?
- How can I set a PostgreSQL interval to zero?
- How can I troubleshoot zero damaged pages in PostgreSQL?
See more codes...