Questions tagged [jsonb]

The binary iteration of the json data type, specifically implemented for Postgres 9.4 and beyond, stands out primarily due to its enhanced efficiency in performance.

Tips for performing calculations on JSON data within Postgres

I have AdWords report data stored in a Postgres database. Each report is saved in a table called Reports with a jsonb column named 'data'. The 'data' field of each report contains JSON that looks like this: [ { match_type: "exact ...

Insert a new key with a value into PostgreSQL only if it does not already exist. If the key exists, update its

Having an issue with updating columns that have NULL values or do not contain a specific key. Here is the code I am trying to run: update A a set a.jsonbcolumn = ('{"key":' 1 '}') I'm currently using postgres version 9.6.3 and u ...

Storing and accessing nested JSONB data in PostgreSQL within a Rails form

Upon realizing the lack of information on utilizing rails forms to store and retrieve JSON data, I encountered a specific issue: Within my form, I am creating a nested structure in JSON: = form_for(@car) do |cf| = cf.fields_for :locations do | locati ...

Converting an array of JSONs in Postgresql to a single JSON object indexed by ID

If I have an array of jsonb in a SQL function with the following format: [{id: 1, name: John}, {id: 2, name: Jane}] My goal is to convert this structure into a single jsonb using the ids as keys: { 1: {id: 1, name: John}, 2: {id: 2, name: Jane} } ...

How can you choose several keys at once from a JSON field using the ->> or #>> operators?

When working with the JSON field below: '{"firstname": "John", "secondname": "Smith", "age": 55}' Is there a way to select specific keys from the array, such as {"firstname", "secondname&quo ...

Looking for data in PostgreSQL using JSON structure

As I consider storing data in a postgres jsonb data type, the structure could look something like {"name": "Jhon Smith", "emails": ["johnsmith@example.com", "j.smith@example.com"], "phones": ["123456789", "987654321"]}. I am aware that I can search this ...

Exploring and organizing JSON data with PostgreSQL

I have a database table named api_details where I store a JSON value in the column raw_data. Now, I want to generate a report based on this JSON data with an expected outcome like the following: action_name sent_timestamp Sent ...

Use jsonb_agg instead of wrapping objects with "jsonb_build_object"

I have found a way to create JSON objects using jsonb_build_object according to my desired format. For example: SELECT jsonb_build_object('id', id) FROM (SELECT generate_series(1,3) id) objects; The result is as follows: jsonb_build_object ------------- ...

What is the best method for saving this object to an SQL database?

As a newcomer to this game, I am curious to know if it's feasible to store the following object in a single column within an SQL database like postgres: { "foo1": ["bar1", "bar2"], "foo2": ["bar1 ...

Is it possible to search and index nested object keys in JSON using PostgreSQL?

If my database table 'configurations' contains rows with a 'data' column in JSONB format like the example below: { "US": { "1234": { "id": "ABCD" } }, "CA": { ...

"Querying a Postgres JSONB integer array to see if it contains any of the specified

Summary: How can I locate all records that have a JSON number array containing one specific number from a given list? I've put in a lot of effort and gone through numerous discussions, but I haven't come across a working solution yet. In Postgre ...