hstore

Renaming hstore key in PostgreSQL 9.2

放肆的年华 提交于 2019-12-22 03:52:40
问题 I've been evaluating PostgreSQL's hstore functionality (9.2) and the only thing the fine manual isn't explicit about is how to rename keys. For instance, how could I rename the key c to ai_count ? "c"=>"3", "ai_voltage"=>"3", "ai_temperature"=>"28" I'm thinking there is no direct way to do this and that it involves duplicating the c key to a ai_count key, then dropping the c key. How can I do this, ideally as a one-liner which can be applied to multiple records? 回答1: I think you're right that

PG::UndefinedObject: ERROR: type “hstore” does not exist but it does

邮差的信 提交于 2019-12-19 19:59:26
问题 First of all, this may look like a duplicate of: postgres hstore exists and doesn't exist at same time but it is not. While I am getting the same error message in the circumstance. When checking to see if hstore is installed on the DB, we can see that it is: ./psql -d photographerio_development -c '\dx' List of installed extensions Name | Version | Schema | Description ---------+---------+------------+-------------------------------------------------- hstore | 1.2 | hstore | data type for

How to write into PostgreSQL hstore using Spark Dataset

折月煮酒 提交于 2019-12-19 08:31:31
问题 I'm trying to write a Spark Dataset into an existent postgresql table (can't change the table metadata like column types). One of the columns of this table is of type HStore and it's causing trouble. I see the following exception when I launch the write (here the original map is empty which when escaped gives an empty string): Caused by: java.sql.BatchUpdateException: Batch entry 0 INSERT INTO part_d3da09549b713bbdcd95eb6095f929c8 (.., "my_hstore_column", ..) VALUES (..,'',..) was aborted.

Installing hstore extension in django nose tests

浪尽此生 提交于 2019-12-18 15:55:25
问题 I've installed the hstore extension successfully, and everything works when I syncdb . (I'm using djorm-ext-hstore) However, nose creates a new temp database to run tests in, and hstore is not installed in it. I need to run CREATE EXTENSION HSTORE; on the test db right before nose syncs the db, but I can't find any info on how to do that. Any ideas? 回答1: This is a non-issue: The best way to fix this is to apply the hstore extension on the default database, template1 psql -d template1 -c

activerecord-postgres-hstore after save error ordering in Hash

拟墨画扇 提交于 2019-12-14 03:56:59
问题 store as Hash Table with Hstore, wrong ordering in Hash after Save class Service < ActiveRecord::Base serialize :properties, ActiveRecord::Coders::Hstore end service = Service.new service.properties = { "aaa" => 1, "zz" => 2, "cc" => 3, "d" => 4 } #=> { "aaa" => 1, "zz" => 2, "cc" => 3, "d" => 4 } service.save reload! service = Service.find(:id) service.properties #=> { "d" => "4", "cc" => "3", "zz" => 2, "aaa" => 1 } Bug::: wrong ordering after save Is it because after serialize that it

Index in hstore with no predictable key

这一生的挚爱 提交于 2019-12-12 20:34:48
问题 Lets say I have a blog database where posts table stores tags in hstore. Keys represent tag ids and values are tag names. ex : 1=>'Test', 56=>'SQL', 42=>'Java' I want to have optimized selects on posts with tag filter. How and what type of select should I create on tags column in order to optimize this query SELECT * FROM posts WHERE tags?'4' The issue is that I don't have predictable key names on order to create index based on their value. Would it be a good solution to create gist index on

Storing nested Hashes in PostgreSQL with Rails 4 (and Hstore)

天涯浪子 提交于 2019-12-12 10:33:06
问题 I have a Rails app that aggregates a lot of data from Google API's. I store the JSON responses in MongoDB currently (so my Rails app has both pg and mongo). However, today, I've came across PostgreSQL Hstore extension, and I've decided to give it a try. Unfortunately, I've ran into a problem. JSON given by API's is multiple levels deep, so Ruby Hash after JSON.parse contains hashes, which contain new hashes. However, Hstore is string key/value store, and it only goes 1 level deep. So hashes

how to parse and display hstore key/value in rails

情到浓时终转凉″ 提交于 2019-12-11 18:14:17
问题 I'ved got a data type that is postgres hstore that stores a json string. I want to be able to parse and display the key/values on rails html page. Somehow, I just do not know how to run a parse on the data field and display each one of key/value listed in the string. <% @payment_accounts.each do |payment_account| %> <tr> <td><%= payment_account.name %></td> <td><%= payment_account.company %></td> <td><%= payment_account.data %></td> <-- this is the hstore json string <td><%= Json.parse

Model attribute contains collection of object

淺唱寂寞╮ 提交于 2019-12-11 13:25:39
问题 I have main model Page, which is container. The page can have some to-do lists, notes, files and discussions. The idea is to have them in special order. Page.last.container # [Todolist_obj, Note_obj, File_obj, Note_obj, Discussion_obj, File_obj, File_obj] So I came to approach to use Mongodb Or I also thought about using Postgres with hstore, but don't know will it help or not Or maybe just any database and deserialize all objects when getting page, and serialize objects when saving Or I can

Postgres HStore Errors - Unknown Operator

蓝咒 提交于 2019-12-11 05:59:10
问题 My ruby code: Portfolio.where("data @> (:key => :value)", :key => 'CSJ', :value => '0.1') Generates the following SQL: "SELECT \"portfolios\".* FROM \"portfolios\" WHERE (data @> ('CSJ' => '0.1'))" Comes up with this error: Error: PG::Error: ERROR: operator does not exist: unknown => unknown LINE 1: ...olios".* FROM "portfolios" WHERE (data @> ('CSJ' => '0.1')) HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. : SELECT "portfolios".*