hstore

setting hstore in rails4, dynamic key/values

爱⌒轻易说出口 提交于 2019-11-30 14:15:55
问题 I'm playing around with Hstore for the first time in a rails4 app, and I am using javascript in a form to build out dynamic form fields for the hstore column (:schema) In rails 4 I dont need to add any setter/getter method in my model, correct? In my form i am building dynamic input fields and allowing the user to set the key/value pairs. Much like the Hstore Heroku Demo App So basically my form would have inputs like input name="app[schema][dynamic_key1]" value="whatever value" input name=

Aggregate hstore column in PostreSQL

守給你的承諾、 提交于 2019-11-30 09:21:19
I have a table like this: Table "public.statistics" id | integer | not null default nextval('statistics_id_seq'::regclass) goals | hstore | items: |id |goals | |30059 |"3"=>"123" | |27333 |"3"=>"200", "5"=>"10" | What I need to do for aggregate all values by key in hash? I want to get result like this: select sum(goals) from statistics return |goals | |"3"=>"323", "5"=>"10" | Building on Laurence's answer, here's a pure SQL way to aggregate the summed key/value pairs into a new hstore using array_agg and the hstore(text[], text[]) constructor. http://sqlfiddle.com/#!1/9f1fb/17 SELECT hstore

Indexes on PostgreSQL hstore array columns

大城市里の小女人 提交于 2019-11-29 23:11:44
问题 I know you can create an index on a field in a hstore column. I know you can also create a GIN index on a array column. But what is the syntax to create an index on an hstore array? e.g. CREATE TABLE customer ( pk serial PRIMARY KEY, customer hstore, customer_purchases hstore[] ); Let's say the customer purchases hstore may be a hash like productId -> 1 price -> 9.99 and I have an array of those in the customer_purchases hstore[] I want to create an index on customer.customer_purchases[]->

Aggregate hstore column in PostreSQL

跟風遠走 提交于 2019-11-29 14:37:14
问题 I have a table like this: Table "public.statistics" id | integer | not null default nextval('statistics_id_seq'::regclass) goals | hstore | items: |id |goals | |30059 |"3"=>"123" | |27333 |"3"=>"200", "5"=>"10" | What I need to do for aggregate all values by key in hash? I want to get result like this: select sum(goals) from statistics return |goals | |"3"=>"323", "5"=>"10" | 回答1: Building on Laurence's answer, here's a pure SQL way to aggregate the summed key/value pairs into a new hstore

Use case for hstore against multiple columns

岁酱吖の 提交于 2019-11-29 07:21:18
I'm having some troubles deciding on which approach to use. I have several entity "types", let's call them A,B and C, who share a certain number of attributes (about 10-15). I created a table called ENTITIES, and a column for each of the common attributes. A,B,C also have some (mostly)unique attributes (all boolean, can be 10 to 30 approx). I'm unsure what is the best approach to follow in modelling the tables: Create a column in the ENTITIES table for each attribute, meaning that entity types that don't share that attribute will just have a null value. Use separate tables for the unique

Can I store arrays in hstore with Rails

丶灬走出姿态 提交于 2019-11-29 05:31:10
I want to save data like this: User.create(name:"Guy", properties:{url:["url1","url2","url3"], street_address:"asdf"}) Can I do so in Rails 4? So far, I have tried migration: add_column :users, :properties, :hstore, array: true But when I save the array in hstore, it returns error: PG::InvalidTextRepresentation: ERROR: array value must start with "{" or dimension information hstore is intended for simple key/value storage, where both the keys and values are simple unstructured strings. From the fine manual : F.16. hstore This module implements the store data type for storing sets of key/value

How to setup django-hstore with an existing app managed by south?

旧城冷巷雨未停 提交于 2019-11-29 00:10:35
问题 I tried to use django-hstore using this nice tutorial. I added two classes to an existing app managed by South: class Attribute(models.Model): name = models.CharField(max_length=200, verbose_name=_("name")) description = models.CharField(max_length=1000, verbose_name=_("description")) class Measure(models.Model): attribute = models.ForeignKey(Attribute) data = hstore.DictionaryField(db_index=True) objects = hstore.HStoreManager() made a schemamigration --auto , launched the migration and got

rails 4 strong params + dynamic hstore keys

左心房为你撑大大i 提交于 2019-11-28 21:31:18
I'm having a problem overcoming the new strong params requirement in Rails 4 using Hstore and dynamic accessors I have an Hstore column called :content which I want to use to store content in multiple languages, ie :en, :fr , etc. And I don't know which language upfront to set them in either the model or the controller. store_accessor :content, [:en, :fr] #+226 random other il8n languages won't work. How can I override strong params (or allow for dynamic hstore keys) in rails 4 for one column? params.require(:article).permit( :name, :content, :en, :fr #+226 random translations ) Short of...

Key value pair in PostgreSQL [closed]

◇◆丶佛笑我妖孽 提交于 2019-11-28 10:56:29
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I need to save key value pairs in PostgreSQL database which will have some basic info regarding the record. After some googling on the topic I found out hstore is one of the options. But even after going through

Why can only a superuser CREATE EXTENSION hstore, but not on Heroku?

大兔子大兔子 提交于 2019-11-28 08:03:38
When I attempt to enable hstore on my database: => CREATE EXTENSION IF NOT EXISTS hstore; ERROR: permission denied to create extension "hstore" HINT: Must be superuser to create this extension. My user is not a superuser, but is the owner of the database. According to the CREATE EXTENSION docs : Loading an extension requires the same privileges that would be required to create its component objects. For most extensions this means superuser or database owner privileges are needed. The user who runs CREATE EXTENSION becomes the owner of the extension for purposes of later privilege checks, as