jsonb

How to convert sql-text to jsonb-string?

血红的双手。 提交于 2020-12-15 00:48:35
问题 There does not seem to be an obvious way: select 'a123'::text::jsonb = ERROR: invalid input syntax for type json select '"a123"'::text::jsonb = BAD string because quoted check select '"a123"'::text::jsonb = ('{"x":"a123"}'::jsonb)->'x' to see that non-quoted is the correct . select '123'::text::jsonb = ('{"x":123}'::jsonb)->'x'; = NOT string I need '123' and 'a123' as pure JSONb strings . PS: it is not a duplicate of generic automatic-anything conversion. 回答1: To convert untyped string

How to convert sql-text to jsonb-string?

不羁的心 提交于 2020-12-15 00:47:12
问题 There does not seem to be an obvious way: select 'a123'::text::jsonb = ERROR: invalid input syntax for type json select '"a123"'::text::jsonb = BAD string because quoted check select '"a123"'::text::jsonb = ('{"x":"a123"}'::jsonb)->'x' to see that non-quoted is the correct . select '123'::text::jsonb = ('{"x":123}'::jsonb)->'x'; = NOT string I need '123' and 'a123' as pure JSONb strings . PS: it is not a duplicate of generic automatic-anything conversion. 回答1: To convert untyped string

[]string to jsonb with Gorm and postgres

大兔子大兔子 提交于 2020-11-29 03:12:31
问题 I have a Go struct which contains a slice of strings which I'd like to save as a jsonB object in Postgres with GORM. I've come accross a solution which requires to use the GORM specific type (postgres.Jsonb) which I'd like to avoid. When I try to run the AutoMigrate with a slice in my model, it panics and won't start although when I wrap this slice in a struct (which I'm okay doing) it will run without error but won't create the column in postgres. type User struct { gorm.Model Data []string