hstore

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

How to access a HSTORE column using PostgreSQL C library (libpq)?

廉价感情. 提交于 2021-01-28 02:56:42
问题 I cannot find any documentation regarding HSTORE data access using the C library. Currently I'm considering to just convert the HSTORE columns into arrays in my queries but is there a way to avoid such conversions? 回答1: libpqtypes appears to have some support for hstore . Another option is to avoid directly interacting with hstore in your code. You can still benefit from it in the database without dealing with its text representation on the client side. Say you want to fetch a hstore field;

How to create an Hstore column type in Laravel 4?

谁说我不能喝 提交于 2020-02-22 08:21:38
问题 I'm using the Schema Builder inside of Migrations in Laravel 4 to manage my Postgres database during development. I've run into a problem. I want to utilize the Postgres Hstore column type in my table but I can't figure it out. There doesn't seem to be a "custom" column type in the Schema Builder (that I can find), so this was my attempt inside of a migration. This didn't work for me. Schema::create('entities', function(Blueprint $table) { $table->bigIncrements('id'); $table->string('type');

Order by a value of an arbitrary attribute in hstore

自古美人都是妖i 提交于 2020-01-04 04:47:17
问题 I have records like these: id, hstore_col 1, {a: 1, b: 2} 2, {c: 3, d: 4} 3, {e: 1, f: 5} How to order them by a maximum/minimum value inside hstore for any attribute? The result should be like this(order by lowest): id, hstore_col 1, {a: 1, b: 2} 3, {e: 1, f: 5} 2, {c: 3, d: 4} I know, I can only order them by specific attribute like this: my_table.hstore_fields -> 'a' , but it doesn't work for my issue. 回答1: Convert to an array using avals and cast the resulting array from text to ints.

Cast JSON to HSTORE in Postgres 9.3+?

本小妞迷上赌 提交于 2020-01-03 16:00:36
问题 I've read the docs and it appears that there's no discernible way to perform an ALTER TABLE ... ALTER COLUMN ... USING statement to directly convert a json type column to an hstore type. There's no function available (that I'm aware of) to perform the cast. The next best alternative I have is to create a new column of type hstore , copy my JSON data to that new column using some external tool, drop the old json column and rename the new hstore column to the old column's name. Is there a

unique index or constraint on hstore key

依然范特西╮ 提交于 2020-01-02 02:21:10
问题 I would like to create a unique index or constraint on a specific keys in an hstore column if that key exists. I was hoping the answer would be found somewhere in this other question: Practical limitations of expression indexes in PostgreSQL But I tried every version of the syntax I could come up with and nothing would work. currently, my table is hstore_table the hstore field is hstore_value and they keys I would like to force to be unique are 'foo' and 'bar' when they exist. My version of

No operator matches the given name and argument type(s)

╄→гoц情女王★ 提交于 2019-12-24 14:33:52
问题 I set up my Rails 3.2.x app to use PostgreSQL HStore but I'm getting an error. It looks like the hstore extension hasn't been picked up by the environment. I already rebooted my machine, checked database extensions, etc. When I try to execute: User.where("settings @> (:key => :value)", :key => "setting_x", :value => "test") I get an error: ( @> is not recognized, i.e., extension hstore is not installed?) HINT: No operator matches the given name and argument type(s). You might need to add

Race condition using Postgres hstore

我是研究僧i 提交于 2019-12-24 11:37:46
问题 I have a table which has amongst many other fields one hstore db/schema.rb create_table "requests", force: true do |t| t.hstore "parameters" end Some of the records have a field parameters["company_id"] but not all of them. What I need to do is to make sure that only one Request object is created with a given parameters["company_id"] . There might be multiple attempts trying to save a record at the same time - thus the race condition. I am looking for unique company_id values inside the

Can I use ActiveRecord relationships with fields from an Hstore?

对着背影说爱祢 提交于 2019-12-22 18:22:01
问题 Can I tie a model to another through active record belongs_to using a field from an hstore hash? I'll elaborate: I have a User model that gets subclassed via STI on one of its fields to many different other User models based on permissions: class User < ActiveRecord::Base self.inheritance_column = :role #other definitions and validations end Here's one such submodel, the nightclub_boss model, meant for administrative users for my app: class NightclubBoss < User belongs_to :nightclub #the boss

simple_form and hstore basic functionality

两盒软妹~` 提交于 2019-12-22 18:15:33
问题 I can get hstore to work with simple_form but all but the most basic functionality (saving) just doesn't work. Validation messages don't show up on the individual fields... all hstore fields oddly show as required, even the values themselves don't populate correctly unless set manually. I have to do something like this: <%= f.simple_fields_for :phones do |phone| %> <%= phone.input :agent, :input_html => { :value => @artist.phones['agent'] } %> <% end %> I have to use simple_fields_for for the