jsonb

Use Storext (or just Virtus) with nested array or hash objects

流过昼夜 提交于 2021-02-19 05:32:18
问题 I have a postgres DB backing my Rails app with a class with a jsonb column class Product < AR::B include Storext.model(data: {}) store_attributes :data do thing_one String thing_two Boolean # Not actually showing up in the `data` hash foos FooCollection[Foo] end end class FooCollection < Array def <<(obj) if Hash super(Coupon.new(obj) else # Other coersions end end end class Foo include Storext.model attribute :id, Integer attribute :price, Float attribute :regular_price, Float end But Foo in

java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy BUG排查

杀马特。学长 韩版系。学妹 提交于 2021-02-18 02:25:18
将某个子项目从war包转化为jar包打包方式后。忘记修改pom.xml中对servlet-api等的修改。 <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>8.0</version> <scope>provided</scope> </dependency> 因此在开发环境中,因为ecplise中自带有javaee-api包。没有发现任何问题,然后在用java -jar方式中运行时,出现BUG java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy 在类似服务器部署环境没法进行debugger的条件下,正好这两天看了 arthas 可以类似aop,监听某方法的调用等。刚好能查看一下这个莫名奇妙的异常信息。 arthas 的操作主要有两步: 打开 arthas options unsafe (对系统级别的类进行增强)。因为sun.reflect.annotation.TypeNotPresentExceptionProxy类是系统类,直接watch监听会报No class or method is affected; watch sun.reflect

Convert JSON string to JSONB

守給你的承諾、 提交于 2021-02-11 16:41:49
问题 I have a table with jsonb field. Some of the rows are an array of objects, but some of the others are string. I want to convert red rows to array of objects. My table structure: How I can do this in PostgreSQL ? 回答1: Following SQL should do the trick: update your_table_name set content = (content#>>'{}')::jsonb where jsonb_typeof(content)='string'; Reference: https://www.postgresql.org/docs/10/functions-json.html 来源: https://stackoverflow.com/questions/60824247/convert-json-string-to-jsonb

How to query in jsonb postgresql and convert to predicate JPA

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-11 14:47:56
问题 i have stuck :) does anyone know how query postgresql in jsonb i have table USER INT id, Varchar name, jsonb categoryId the example data in categoryId field like this = [1,2,3,4,5] I have tried this query which works: select * from user where categoryId @> '2'::jsonb ; but how to query with multiple params like select * from user where categoryId @> '1,3,4'::jsonb and i will implement this to hibernate jpa/jpql-predicate, but i want to know native query first Thankyou so much 回答1: In SQL you

Postgresql update a value in a jsonb array column

这一生的挚爱 提交于 2021-02-11 14:45:11
问题 I have one table with a jsonb and this data inside: [ { "valor": "2025,79", "parcela": 46, "vencimento": 1570503600000 }, { "valor": "1987,7", "parcela": 47, "vencimento": 1573182000000 }, { "valor": "1950,47", "parcela": 48, "vencimento": 1575774000000 }, { "valor": "1912,88", "parcela": 49, "vencimento": 1578452400000 } ] but now I need in all row, alter the value in "vencimento" from 1573182000000 to "10/10/2010" it's possible ? with this code I can split the array in columns and change te

Postgresql - Count freuency of array or jsonb object

有些话、适合烂在心里 提交于 2021-02-11 12:15:20
问题 In pg, there is a tags field of type varchar , containing tags separated by ] , e.g 'a]b]c' . Need to count occurrences of these tags across multiple rows. Currently , I know how to: Convert the raw string into pg array ['a', 'b', 'c'] and if the column is given as jsonb object {'a':1, 'b':1, 'c':1} , could count frequency via jsonb functions. But I don't know how to convert pg array ['a', 'b', 'c'] into jsonb object {'a':1, 'b':1, 'c':1} , or just count frequency on array elements directly.

Filter rows based on values inside multiple JSONB columns

…衆ロ難τιáo~ 提交于 2021-02-10 15:49:36
问题 I am trying to search a table in a LIKE %str% fashion but on fields inside json values over multiple columns . I have a table which has three jsonb columns change , previous and specific_changes . As you might imagine the content is JSON but the structure of that json is not know ahead of time, therefor i can't use the -> or ->> in query like so: select * from change_log where change -> 'field' = '"something"' create table change_log ( id serial not null constraint pk_change_log primary key,

cannot extract elements from a scalar

寵の児 提交于 2021-02-09 09:20:13
问题 I have 2 tables company and contacts. Contacts has addresses JSONB column. I tried a select statement with a join on contacts.linked_to_company and using jsonb_array_elements(company.addresses) but I get error 'cannot extract elements from a scalar' which I understand is because some entries do have [null] in column address. I have seen answers to use coalesce or a CASE statement. Coalesce I could get to not work and CASE example is in the select statement how do use it in a join? Here is the

cannot extract elements from a scalar

狂风中的少年 提交于 2021-02-09 09:14:10
问题 I have 2 tables company and contacts. Contacts has addresses JSONB column. I tried a select statement with a join on contacts.linked_to_company and using jsonb_array_elements(company.addresses) but I get error 'cannot extract elements from a scalar' which I understand is because some entries do have [null] in column address. I have seen answers to use coalesce or a CASE statement. Coalesce I could get to not work and CASE example is in the select statement how do use it in a join? Here is the

Postgresql: query on jsonb column - index doesn't make it quicker

∥☆過路亽.° 提交于 2021-02-09 08:34:31
问题 There is a table in Postgresql 9.6 , query on jsonb column is slow compared to a relational table, and adding a GIN index on it doesn't make it quicker. Table: -- create table create table dummy_jsonb ( id serial8, data jsonb, primary key (id) ); -- create index CREATE INDEX dummy_jsonb_data_index ON dummy_jsonb USING gin (data); -- CREATE INDEX dummy_jsonb_data_index ON dummy_jsonb USING gin (data jsonb_path_ops); Generate data: -- generate data, CREATE OR REPLACE FUNCTION dummy_jsonb_gen