Questions tagged [hstore]

hstore is data type for storing sets of key/value pairs in Postgres, similar to hashes in Ruby and Perl, associative arrays in PHP or dictionaries in Python.

The hstore PostgreSQL module implements a data type for storing sets of key/value pairs within a single PostgreSQL value. It can be used similar to how you would use a dictionary within another language, though it's specific to a column on a row. This can be useful in various scenarios, such as rows with many attributes that are rarely examined, or semi-structured data. Keys and values are simply text strings.

Example: To enable HStore on postgres, use:

CREATE EXTENSION hstore;

also mention attributes hstore while creating the table as shown below:

CREATE TABLE products (
  id serial PRIMARY KEY,
  name varchar,
  attributes hstore
);
469 questions
62
votes
2 answers

How to create a new database with the hstore extension already installed?

Recently I went into trouble trying to use hstore with Django. I installed hstore this way: $ sudo -u postgres psql postgres=# CREATE EXTENSION hstore; WARNING: => is deprecated as an operator name DETAIL: This name may be disallowed altogether in…
Maxime R.
  • 9,621
  • 7
  • 53
  • 59
36
votes
3 answers

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

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…
Peeja
  • 13,683
  • 11
  • 58
  • 77
24
votes
1 answer

Updating a single key/value pair in a Rails 4 and PostgreSQL json column?

I have a rather large json document that I have to store in a field for each Evaluation instance in my app. The over time, certain actions on the app will require me to change various key/value pairs in the document. The Rails 4 and PostgreSQL json…
Randy Burgess
  • 4,835
  • 6
  • 41
  • 59
23
votes
1 answer

When should HStoreField be used instead of JSONField?

Django 1.8 provides HStoreField and Django 1.9 will provide JSONField (which uses jsonb) for PostgreSQL. My understanding is that hstore is faster than json, but does not allow nesting and only allows strings. When should one be used over the other?…
mcastle
  • 2,882
  • 3
  • 25
  • 43
23
votes
2 answers

How to query values with wildcards in PostgreSQL hstore

I'm trying to query hstore for all the values of a certain key that match a search criteria. I can get all the values for a certain key like this: SELECT DISTINCT svals(slice(data, ARRAY['Supplier'])) FROM "products" I can also get a specific…
Rob Gonzalez
  • 579
  • 1
  • 6
  • 19
23
votes
3 answers

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

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 =…
Maxime R.
  • 9,621
  • 7
  • 53
  • 59
22
votes
2 answers

Postgresql JSONB is coming. What to use now? Hstore? JSON? EAV?

After going through the relational DB/NoSQL research debate, I've come to the conclusion that I will be moving forward with PG as my data store. A big part of that decision was the announcement of JSONB coming to 9.4. My question is what should I…
Mike
  • 558
  • 5
  • 13
21
votes
3 answers

Can I store arrays in hstore with Rails

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…
Ivan Wang
  • 8,306
  • 14
  • 44
  • 56
20
votes
1 answer

Most efficient way to retrieve a unique list of keys from all rows of an hstore?

For simplicity sake, say I have a table with a single column that is just an hstore. What is the most efficient way to go about getting a unqiue list of all the keys from all rows of the…
jay.lee
  • 19,388
  • 8
  • 39
  • 38
19
votes
1 answer

Passing column names dynamically for a record variable in PostgreSQL

Using PostgreSQL, column values from a table for 1st record are stored in a record variable. for ex: let the variable be: recordvar recordvar.columnname gives the value of the column name specified. I will define the columname in a variable: var :=…
user2664380
  • 289
  • 1
  • 4
  • 8
18
votes
3 answers

How to use PostgreSQL hstore/json with JdbcTemplate

Is there a way to use PostgreSQL json/hstore with JdbcTemplate? esp query support. for eg: hstore: INSERT INTO hstore_test (data) VALUES ('"key1"=>"value1", "key2"=>"value2", "key3"=>"value3"') SELECT data -> 'key4' FROM hstore_test SELECT…
Aymer
  • 321
  • 1
  • 4
  • 11
18
votes
3 answers

How can I update a data record's value with Ruby on Rails 4.0.1/PostgreSQL Hstore?

I'm encountering a strange issue that must be user error on my part but can't figure it out. I'm using Ruby 1.9.3-p194, Rails 4.01, PostgreSQL. I have a model, Customer, with a column called data that is a hstore type. For some reason, I am not able…
james
  • 491
  • 6
  • 15
16
votes
1 answer

rails 4.1 validation of arbitrary fields via hstore

I use HStore in Rails 4.1 to manage I18n and storage of languages. It works great the only problem I have is I would like to do something like this (instead of using store_accessor) In Rails 4.0 this worked…
holden
  • 13,471
  • 22
  • 98
  • 160
16
votes
2 answers

Setting up Discourse on Ubuntu 12.04 LTS

I have setup a new database for installing Discourse in PostgreSQL. When I run rake db:migrate, it creates most of the tables, but it then fails: -- execute("INSERT INTO archetypes (name_key, created_at, updated_at) VALUES ('poll',…
15
votes
1 answer

Best PostgreSQL datatype for storing key-value maps?

I'd like to store a simple map of key-value strings as a field in my PostgreSQL table. I intend to treat the map as a whole; i.e, always select the entire map, and never query by its keys nor values. I've read articles comparing between hstore, json…
Eyal Roth
  • 3,895
  • 6
  • 34
  • 45
1
2 3
31 32