Hey Jeremy,
sorry for late response. I am having exactly same issues with json 
extension. Simply it seems, that you can't modify 
`Sequel::Postgres::JSONHash` and `Sequel::Postgres::HStore` directly like 
`model.json_attr[:key] = true`, or `model.hstore_attr[:key] = true`

What works for me is `model.json_attr = model.json_attr.to_hash.merge(key: 
true)` so i must reassign whole pure hash. Everything else works as 
expected. I have issues just with this direct manipulation.

Petr

On Wednesday, July 23, 2014 4:55:37 PM UTC+2, Jeremy Evans wrote:
>
> On Tuesday, July 22, 2014 11:27:12 PM UTC-7, Petr Kaleta wrote:
>>
>> Hey, I have model with hstore attribute.
>>
>> Creating model works with no issues:
>>
>> m = MyModel.new
>> m.hstoreAttr = {foo: 'bar'}
>> m.save
>>
>> But once doing a update:
>>
>> m = MyModel[1]
>> m.hstoreAttr[:foo] # => "bar"
>> m.hstoreAttr[:foo] = 'baaaaar'
>> m.save
>>
>> I receive following error:
>>
>> Sequel::Error: can't express 
>> #<Java::OrgPostgresqlUtil::PGobject:0x6b95d875> as a SQL literal
>>
>
> Since the it works if you reassign the attribute, that indicates that you 
> have loaded the pg_hstore extension into your Sequel::Database object 
> correctly, because the schema type is getting recognized.
>
> The fact that it doesn't automatically convert hstore types into 
> Sequel::Postgres::HStore instances on retrieval indicates that the 
> Sequel::Database object does not have the hstore oid associated with the 
> hstore conversion proc.  This usually happens automatically, I'm not sure 
> why it isn't happening in your case.  The only thing I can think of is you 
> have turned of type conversion in the jdbc adapter (DB.convert_types = 
> false), in which case this would be expected.  I'm assuming that isn't true.
>
> To troubleshoot, try to put together the simplest example:
>
>   DB = Sequel.connect("postgres:///...")
>   DB.extension :pg_hstore
>   p DB.get(Sequel.lit("'a=>b'::hstore")).class
>
> If that doesn't print Sequel::Postgres::HStore, then that is a problem. 
>  In that case, run this code to get the hstore oid:
>
>   p DB.from(:pg_type).where(:typtype=>'b', 
> :typname=>'hstore').select_map([:oid, :typname])
>
> Also, run this code to get the schema for the table:
>
>   p DB.schema(:table_name)
>
> Post the results here and hopefully we can find the underlying issue.
>
> 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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to