hstore

fabricator with hstore attribute

雨燕双飞 提交于 2019-12-11 02:59:57
问题 I am trying to build a fabricator using 'fabrication', '2.8.1' with a hstore attribute. Fabricator(:inventory_item_change) do attribute_changes Hash.new("num_units" => "to:50") state "scheduled" change_code 1 execution_at Time.now.advance(days: 3) inventory_item end This is the error message I am receiving when running tests with this fabricator. I've isolated the problem to be the hstore attribute: attribute changes. Failure/Error: attr = Fabricate.attributes_for(:inventory_item_change)

Is there a way to query a PostgreSQL hstore with Hibernate/JPQL?

倖福魔咒の 提交于 2019-12-10 13:09:18
问题 Assuming I have a Hibernate/JPA Entity like the following: @Entity public class FooEntity { ... @Type(type = "hstore") HashMap<String, String> tags; } ... and the hstore Type is a simple UserType implementation from this resource. Is there a way to access the hstore in a JPQL query similar to this Pseudocode: SELECT f FROM FooEntity f WHERE f.tags CONTAINS KEY(:key) 回答1: Hibernate offers a common query abstraction across many DBs so a non-SQL syntax is hard to be abstracted out. I would go

Return records that don't have specific key - Rails4 HStore Postgresql query

为君一笑 提交于 2019-12-10 11:15:59
问题 I have a model Task t.string "name" t.hstore "actions" Example: #<Task id: 1, name: "first", actions: {"today"=>"9"}, #<Task id: 2, name: "second", actions: {"yesterday"=>"1"}, #<Task id: 3, name: "third", actions: nil, #<Task id: 4, name: "four", actions: {"today"=>"11"}, I need to find all records where actions: nil, :today<10 and key :today not present. It is 1,2,3 task. Task.where("actions -> 'today' < '10'") - it return only first task. Task.where("actions -> 'today' < '10' OR actions IS

Create HSTORE with multiple schemas

狂风中的少年 提交于 2019-12-10 10:37:48
问题 I have been trying to migrate my database to have HSTORE but the extension only works for public SCHEMA when I want to add an HSTORE column in other schemas it does not work def up # My hstore looks like this execute "CREATE EXTENSION hstore SCHEMA public" # I have also tried # execute "CREATE EXTENSION hstore" end but when I run my next migration it just doesn't work and if I go to psql console and alter tables I get this: set search_path to public; alter table accounts add column extras

Should I use hstore in renewed data model?

匆匆过客 提交于 2019-12-07 23:40:04
问题 In my legacy database (Postgres 9.1) I have several tables containing divers kinds of documents (let's say they are 'parent' tables). Additionally, there is a table with various parameters for these documents: create table params ( kind integer, docid integer, parname text, parvalue text, constraint params_pk primary key (kind, docid, parname)); There may be many (parname, parvalue) pairs for one document. As kind points to different tables it cannot be used as a foreign key. It has been

Convert a stringified array back to array

耗尽温柔 提交于 2019-12-07 09:03:14
问题 I use hstore with Postgres 9.2 and Rails 3.2 to store my object like this: class User user_hstore = {:user_id =>"123", :user_courses => [1,2,3]} end Now, when I retrieve user_courses, I get a string like this: '[1, 2, 3]' How do I convert this string to Rails array? Better yet, is there a way to store an array within a hstore object so that Rails will automatically retrieve it as array type? 回答1: JSON.parse "[\"1018\", \"1037\", \"1045\", \"1042\"]" #=> ["1018", " 1037", " 1045", " 1042"] 回答2

simple_form and hstore basic functionality

筅森魡賤 提交于 2019-12-06 13:32:00
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 hstore hash and it saves properly but on edit the values don't populate without using the input_html

How to create an Hstore column type in Laravel 4?

大憨熊 提交于 2019-12-06 13:18:56
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'); $table->string('name'); $table->text('data')->nullable(); $table->timestamps(); $table->softDeletes();

Hstore and Rails

久未见 提交于 2019-12-06 12:13:09
问题 I'm trying to use Hstore in a Rails 3.2.9 project using the latest version of the activerecord-postgres-hstore gem and I am having a bit of trouble using the store_accessor provided by ActiveRecord for the values in the Hstore. My model looks like this: class Person < ActiveRecord::Base serialize :data, ActiveRecord::Coders::Hstore attr_accessible :data, :name store_accessor :data, :age, :gender end When I go into the rails console here's what I get: Loading development environment (Rails 3.2

Select column name and value from table

Deadly 提交于 2019-12-06 11:07:34
问题 If I have the following table in a PostgreSQL database: Col1 Col2 Col3 A a 1 B b 2 Is there a way to get the column name for each value without explicitly specifying the column names ? I.e. have a result set like: Col1 A Col1 B Col2 a Col2 b Col3 1 Col3 2 回答1: Of course, you could write a PL/pgSQL function and query the catalog table pg_attribute yourself. But it's so much easier with one of the following: JSON The function row_to_json() provides functionality that goes half the way.