On Tuesday, August 5, 2014 4:15:27 PM UTC+1, Jeremy Evans wrote:
>
> On Tuesday, August 5, 2014 4:10:20 AM UTC-7, Paul Carew wrote:
>>
>> Hi
>>
>> First time Sequel user here and I've got an issue I was hoping someone
>> could help me with.
>>
>> I am using the pg_array extension and am registering it with...
>>
>> DB.extension :pg_array
>>
>> When creating models from JSON data it works fine.
>>
>> record = MyModel.new(jsonString)
>> record.save
>>
>> However, when I load a record and try to update it.
>>
>> record = MyModel.where(:id => 1)
>>
>> if record.count == 1 then
>> record.update(jsonString)
>> end
>>
>> It fails with the following error:
>>
>> Sequel::DatabaseError - PG::InvalidTextRepresentation: ERROR: array
>> value must start with "{" or dimension information
>> LINE 1: ...nsferredTo" = NULL, "priority" = '1', "seenBy" = ('1'), "equ...
>> ^
>> It doesn't look like this is correctly picking up that the "seenBy" field
>> is an array but this appears to fine when calling Model.new().
>>
>> I've been trying to figure out this issue for a while now, I originally
>> tried Slashdot but as nobody was able to assist I thought I might be better
>> asking here. Any pointers would be greatly appreciated.
>>
>
> Can you come up with a self-contained example showing the problem?
> There's not enough information here for me to debug.
>
> Thanks,
> Jeremy
>
Thanks for taking a look. The following example should illustrate the issue.
require "sequel"
# Setup Sequel connection to postgres
DB = Sequel.connect('postgres://username:password@localhost/database_name')
DB.extension :pg_array
# Define the Record model
class Record < Sequel::Model
plugin :json_serializer
end
# Create the records table if it doesn't exist
if !DB.table_exists? :records
DB.create_table :records do
primary_key :id
text :name
integer :seenBy, :type => "integer[]"
end
end
# JSON representations of data
dataNew = {"name"=>"John Smith", "seenBy"=>["1"]}
dataUpdate = {"name"=>"John Smith", "seenBy"=>["1", "2"]}
#Create a new record
newRecord = Record.new(dataNew)
newRecord.save
#Update record
updatedRecord = Record.where(:id => newRecord.id)
updatedRecord.update(dataUpdate)
When run this generates the following error:
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/sequel-4.13.0/lib/sequel/adapters/postgres.rb:161:in
`async_exec': PG::DatatypeMismatch: ERROR: column "seenBy" is of type
integer[] but expression is of type record (Sequel::DatabaseError)
LINE 1: ...E "records" SET "name" = 'John Smith', "seenBy" = ('1', '2')...
^
HINT: You will need to rewrite or cast the expression.
from
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/sequel-4.13.0/lib/sequel/adapters/postgres.rb:161:in
`block in execute_query'
from
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/sequel-4.13.0/lib/sequel/database/logging.rb:33:in
`log_yield'
from
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/sequel-4.13.0/lib/sequel/adapters/postgres.rb:161:in
`execute_query'
from
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/sequel-4.13.0/lib/sequel/adapters/postgres.rb:148:in
`block in execute'
from
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/sequel-4.13.0/lib/sequel/adapters/postgres.rb:124:in
`check_disconnect_errors'
from
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/sequel-4.13.0/lib/sequel/adapters/postgres.rb:148:in
`execute'
from
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/sequel-4.13.0/lib/sequel/adapters/postgres.rb:492:in
`_execute'
from
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/sequel-4.13.0/lib/sequel/adapters/postgres.rb:316:in
`block (2 levels) in execute'
from
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/sequel-4.13.0/lib/sequel/adapters/postgres.rb:513:in
`check_database_errors'
from
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/sequel-4.13.0/lib/sequel/adapters/postgres.rb:316:in
`block in execute'
from
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/sequel-4.13.0/lib/sequel/database/connecting.rb:250:in
`block in synchronize'
from
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/sequel-4.13.0/lib/sequel/connection_pool/threaded.rb:104:in
`hold'
from
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/sequel-4.13.0/lib/sequel/database/connecting.rb:250:in
`synchronize'
from
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/sequel-4.13.0/lib/sequel/adapters/postgres.rb:316:in
`execute'
from
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/sequel-4.13.0/lib/sequel/database/query.rb:50:in
`execute_dui'
from
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/sequel-4.13.0/lib/sequel/dataset/actions.rb:917:in
`execute_dui'
from
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/sequel-4.13.0/lib/sequel/dataset/actions.rb:773:in
`update'
--
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.