On Friday, April 19, 2013 12:13:47 PM UTC-7, Marc Cooper wrote:
>
> I would like to know the correct way to delete an entry from the hstore.
>
> When I fetch user3 below, I wrap the hstore as an hstore_op as described 
> here: 
> https://github.com/jeremyevans/sequel/blob/master/lib/sequel/extensions/pg_hstore_ops.rb
> However, neither of the deletion methods seem to work.
>
> With user4m, I wrap with hstore, though I believe this is redundant. The 
> deletion works -- I presume via the underlying hash -- but then the updated 
> hstore can't be persisted.
>

There's two different things here.  One is deleting from the hstore object 
(the underlying hash), which works via delete.  The other is producing an 
SQL expression that results in deleting from the hstore in PostgreSQL.

Here's a short example:

DB.extension :pg_hstore
Sequel.extension :pg_hstore_ops
h = DB.get(Sequel.hstore({'a'=>'1', 'b'=>'2'}))

# Have PostgreSQL do the deletion
# The cast is currently necessary because PostgreSQL assumes the string
# is in hstore format otherwise.  I can probably work around that in the
# pg_hstore_op extension.
DB.get(h.op - Sequel.cast('a', String))

# Do the deletion yourself and send PostgreSQL a new hstore
h.delete('a')
DB.get(h)

To actually modify a column value, you'll want to use Dataset#update, not 
#get as shown here.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to