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 thenamefield from themy_jsoncolumn as a JSON objectAS name- assigns the result of the->operator to thenamecolumnmy_json->'age'- uses the->operator to return theagefield from themy_jsoncolumn as a JSON objectAS age- assigns the result of the->operator to theagecolumnFROM my_table- specifies the table to query
Helpful links
More of Postgresql
- How can Zalando use PostgreSQL to improve its software development?
- How can I use PostgreSQL's "zero if null" feature?
- How do I use PostgreSQL and ZFS together?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How can I integrate PostgreSQL with Yii2?
- How do I use PostgreSQL variables in my software development project?
- How can I monitor PostgreSQL performance using Zabbix?
- How do I set up PostgreSQL Kerberos authentication?
- How can I use PostgreSQL with YAML?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
See more codes...