AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Postgres jsonb query8/31/2023 ![]() The query selects the position and object of an Array from the students' table. Jsonb_array_elements(subject_marks) with ordinality arr(item_object, position) Use the following query to expand the subjects_marks field into an array format for a student having id 2: -Array functions to Query JSONB Running the above code displays that the “subject_marks” column contains the subject id, subject name, and their respective marks: The “subject_marks” column contains data for the student in the JSONB data type: Select subject_marks from students Use the following query to get the subject_marks field from the “ students” table. ![]() The above query gets the names from the JSONB data field and displays them as individual objects: Use the following query to use another JSONB operator ( ->) which returns the JSONB object from the emp table: SELECT data -> 'name' AS Name FROM emp The above command fetches names from the data field and displays them in the name field: Use the following command that utilizes the JSONB operator ( ->) to get the data associated with the name key from the JSONB column and retrieve it as text: SELECT data -> 'name' AS Name FROM emp The above query gets the JSONB type data from the emp table where the emp_id column has value 1: Use the following query to get the data using the WHERE clause that filters data with respect to some specific condition: SELECT data FROM emp WHERE emp_id =1 The above query displays the data from the emp table containing JSONB type of column named data: To query the data from the JSONB-type array of objects in PostgreSQL, use the following query: SELECT * FROM emp How to Query JSONB Array of Objects in PostgreSQL? This guide will explain querying the JSONB array of objects in PostgreSQL. JSON format stores data in the form of text and JSONB refers to the binary format of data storage to provide better efficiency. The user can store data in different formats/types like string, integer, character, JSON, JSONB, etc. PostgreSQL allows the user to store their structured data in the databases using rows and columns in the table.
0 Comments
Read More
Leave a Reply. |