jsonb

Update the value of an attribute in a postgresql jsonb array of objects across muliple records

故事扮演 提交于 2020-08-10 20:32:28
问题 I am trying to update a value tit in three database records that is part of a jsonb array object to change the title of gid 1 to 'newTitle Group 1' from just 'group 1' using postgresql and python. create table groups (name varchar, grp jsonb) insert into groups (name, grp) values ('joe', [{"gid": "1", "ona": "joe", "tit": "group 1 "}, {"gid": "2", "ona": "harry", "tit": "tester1 group 2"}, {"gid": "3", "ona": "moe", "tit": "group 3"}]), ('harry', [{"gid": "1", "ona": "joe", "tit": "group 1 "}

Intersection of values of json array in PostgreSQL

假装没事ソ 提交于 2020-08-07 09:09:36
问题 In PostgreSQL 9.4, I have a table like this: id | array_json ---+---------------------------- 1 | [{"type": "single", "field_id": 9}, | {"type": "range", "field_id": 2}, ...] | 2 | [{"type": "single", "field_id": 10}, | {"type": "range", "field_id": 2}, ...] ... I want to get the intersection of all field_id values in array_json column across all table . | field_id intersection +------- | 2 I mean: 1. map field_id values for first row: [9, 2] 2. map field_id values for second row: [10, 2] n.

Deleting a jsonb array item by name

本秂侑毒 提交于 2020-08-05 06:18:45
问题 I have the following table CREATE TABLE country ( id INTEGER NOT NULL PRIMARY KEY , name VARCHAR(50), extra_info JSONB ); INSERT INTO country(id,extra_info) VALUES (1, '{ "name" : "France", "population" : "65000000", "flag_colours": ["red", "blue","white"]}'); INSERT INTO country(id,extra_info) VALUES (2, '{ "name": "Spain", "population" : "47000000", "borders": ["Portugal", "France"] }'); and i can add an element to the array like this UPDATE country SET extra_info = jsonb_set(extra_info, '

Deleting a jsonb array item by name

邮差的信 提交于 2020-08-05 06:17:17
问题 I have the following table CREATE TABLE country ( id INTEGER NOT NULL PRIMARY KEY , name VARCHAR(50), extra_info JSONB ); INSERT INTO country(id,extra_info) VALUES (1, '{ "name" : "France", "population" : "65000000", "flag_colours": ["red", "blue","white"]}'); INSERT INTO country(id,extra_info) VALUES (2, '{ "name": "Spain", "population" : "47000000", "borders": ["Portugal", "France"] }'); and i can add an element to the array like this UPDATE country SET extra_info = jsonb_set(extra_info, '

How to modify or remove a specific JSON object from JSON array stored in jsonb column type in PostgreSQL using where clause?

痞子三分冷 提交于 2020-07-30 04:20:32
问题 In my Postgres database, I have one of the table columns having jsonb datatype. In that column, I am storing the JSON array. Now, I want to remove or modify a specific JSON object inside the array. My JSON array looks like [ { "ModuleId": 1, "ModuleName": "XYZ" }, { "ModuleId": 2, "ModuleName": "ABC" } ] Now, I want to perform two operations: How can I remove the JSON object from the above array having ModuleId as 1? How can I modify the JSON object i.e. change the ModuleName as 'CBA' whose

What is the proper formatting for a jsonb array in Python for Postgres?

吃可爱长大的小学妹 提交于 2020-07-09 07:19:25
问题 I have a schema that looks like Column | Type | ------------------------------------------------------- message_id | integer | user_id | integer | body | text | created_at | timestamp without time zone | source | jsonb | symbols | jsonb[] | I am trying to use psycopg2 to insert data via psycopg2.Cursor.copy_from() but I am getting numerous issues trying to figure out how a jsonb[] object should be formatted. When I do a straight list of JSON objects, I get an error that looks like psycopg2

What is the proper formatting for a jsonb array in Python for Postgres?

怎甘沉沦 提交于 2020-07-09 07:19:06
问题 I have a schema that looks like Column | Type | ------------------------------------------------------- message_id | integer | user_id | integer | body | text | created_at | timestamp without time zone | source | jsonb | symbols | jsonb[] | I am trying to use psycopg2 to insert data via psycopg2.Cursor.copy_from() but I am getting numerous issues trying to figure out how a jsonb[] object should be formatted. When I do a straight list of JSON objects, I get an error that looks like psycopg2

How to create custom jsonb mapper for PostgreSQL and Hibernate in Kotlin?

淺唱寂寞╮ 提交于 2020-06-29 04:13:11
问题 I went through available articles: 1, 2, 3. All of the articles nail down to the following options: Register custom PostgreSQL95Dialect which has jsonb type Implement Hibernate's UserType interface with custom mapping Annotate Entity with @TypeDef of custom implementation Define in application.properties custom dialect If all of the above is done, code is supposed to work. In my case I bump into mysterious Unable to build Hibernate SessionFactory; nested exception is org.hibernate