hstore

How to use PostgreSQL hstore/json with JdbcTemplate

非 Y 不嫁゛ 提交于 2019-12-03 12:49:15
问题 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 item_id, (each(data)).* FROM hstore_test WHERE item_id = 2 for Json insert into jtest (data) values ('{"k1": 1, "k2": "two"}'); select * from jtest where data ->> 'k2' = 'two'; 回答1: Although quite late for an answer (for the insert part), I hope it might

Rails and Postgres Hstore: Can you add an index in a migration?

早过忘川 提交于 2019-12-03 12:24:40
I have a migration where I create a products table like so class CreateProducts < ActiveRecord::Migration def change create_table :products do |t| t.string :name t.hstore :data t.timestamps end end end On the activerecord-postgres-hstore page they add an index to the table (in SQL) with CREATE INDEX products_gin_data ON products USING GIN(data); However that change is not tracked by migrations (I'm guessing because it's Postgres specific?), is there a way to create an index from within a migration? thanks! Yes! You can make another migration and use the 'execute' method... like so: class

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

孤街醉人 提交于 2019-12-03 04:43:23
问题 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 do now, building an application from the ground up knowing that I want to migrate to (I mean use right now!) jsonb? The DaaS options for me are going to be running 9.3 for a while. From what I can tell, and correct me if I'm wrong, hstore would run

How to query values with wildcards in PostgreSQL hstore

…衆ロ難τιáo~ 提交于 2019-12-03 03:51:41
问题 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 value: SELECT DISTINCT svals(slice(data, ARRAY['Supplier'])) AS sup FROM "products" WHERE data @> 'Supplier => Toshiba' What I would really like is something like (this doesn't work): SELECT DISTINCT svals(slice(data, ARRAY['Supplier'])) AS sup FROM

How to use PostgreSQL hstore/json with JdbcTemplate

二次信任 提交于 2019-12-02 23:21:10
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 item_id, (each(data)).* FROM hstore_test WHERE item_id = 2 for Json insert into jtest (data) values ('{"k1": 1, "k2": "two"}'); select * from jtest where data ->> 'k2' = 'two'; sojin Although quite late for an answer (for the insert part), I hope it might be useful someone else: Take the key/value pairs in a HashMap: Map<String, String> hstoreMap = new

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

六眼飞鱼酱① 提交于 2019-12-02 17:12:08
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 do now, building an application from the ground up knowing that I want to migrate to (I mean use right now!) jsonb? The DaaS options for me are going to be running 9.3 for a while. From what I can tell, and correct me if I'm wrong, hstore would run quite a bit faster since I'll be doing a lot of queries of many keys in the hstore column and if I were

How to write into PostgreSQL hstore using Spark Dataset

≯℡__Kan透↙ 提交于 2019-12-01 06:15:13
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. Call getNextException to see the cause. at org.postgresql.jdbc.BatchResultHandler.handleError

Escaping hstore contains operators in a JDBC Prepared statement

半腔热情 提交于 2019-12-01 03:57:34
I am using PostgreSQL 9.1.4 with hstore and the PostgreSQL JDBC driver (9.1-901.jdbc4). I am trying to use the contains operators ( ? , ?& , ?| ) in a PreparedStatement, however the ? character is parsed as a variable placeholder. Can this character be escaped to send the correct operator in the query? An example: PreparedStatement stmt = conn.prepareStatement("SELECT a, b FROM table1 WHERE c ? 'foo' AND d = ?"); stmt.setInt(1, dValue); stmt.executeQuery(); In this form the following example would raise an exception: org.postgresql.util.PSQLException: No value specified for parameter 2. Update

Escaping hstore contains operators in a JDBC Prepared statement

▼魔方 西西 提交于 2019-12-01 00:27:32
问题 I am using PostgreSQL 9.1.4 with hstore and the PostgreSQL JDBC driver (9.1-901.jdbc4). I am trying to use the contains operators ( ? , ?& , ?| ) in a PreparedStatement, however the ? character is parsed as a variable placeholder. Can this character be escaped to send the correct operator in the query? An example: PreparedStatement stmt = conn.prepareStatement("SELECT a, b FROM table1 WHERE c ? 'foo' AND d = ?"); stmt.setInt(1, dValue); stmt.executeQuery(); In this form the following example

Indexes on PostgreSQL hstore array columns

ε祈祈猫儿з 提交于 2019-11-30 16:04:55
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[]-> productId Is this possible? I've tried different combinations of CREATE INDEX syntaxes and none of them