Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

(FIX) Error for array of integers for postgres #10340

Closed
wants to merge 1 commit into from

9 participants

@Slike9

Field description in schema: t.integer :field_name, :type => :array.
Error: "undefined method `gsub' for 1:Fixnum" in PostgreSQLColumn#quote_and_escape.

@Slike9 Slike9 (FIX) Error for array of integers for postgres
Field description in schema: `t.integer :field_name, :type => :array`. 
Error: "undefined method `gsub' for 1:Fixnum" in PostgreSQLColumn#quote_and_escape.
79ff41c
@rafaelfranca

We'll need a test to this

@senny
Owner

@Slike9 ping, what is the status of this PR? Can you add a test-case?

@Slike9

test fails (PostgresqlArrayTest#test_multi_dimensional)

@Slike9 Slike9 closed this
@Numerico

Getting this error on v4.0.0.beta1 too

@arunagw
Collaborator

@Numerico on 4.0.0 too?

@Numerico

that's right. (or you mean to test it against 4.0.0 instead of 4.0.0.beta1?)

i finally by-passed it having an array of strings instead of integers, but I suppose it should work for ints, shouldn't it?

@hubertlepicki

I can confirm this is a problem and the pull request fixes it, so I am unsure why this has been closed. Can someone @Slike9 or @rafaelfranca re-open the issue?

@arunagw arunagw reopened this
@neerajdotname
Collaborator

@hubertlepicki can you describe what problem you ran into. The PR description says it fixes the issue with t.integer :field_name, :type => :array . However that already works in master. Thanks.

@hubertlepicki

Tell you what, I'll make a separate pull request as this is, indeed similar, but slight different issue than described at least in the description here.

@saulius

This issue stops me from upgrading one of the apps to Rails 4. Fix in #11245 seems to resolve the issue. Just wanted to give heads up.

@sevenseacat

Also run into this issue in Rails 4.0.0. On a side note, type: :array did not work for me, I had to use array: true to get AR to even recognize the field as an array.

Changing the field to be of type string instead of integer also resolved the problem.

@alno alno referenced this pull request in jruby/activerecord-jdbc-adapter
Open

Fix compound arrays #464

@senny
Owner

Closing this PR. We have #11245 with a working solution. @Slike9 thanks for your work :yellow_heart:

@senny senny closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 25, 2013
  1. @Slike9

    (FIX) Error for array of integers for postgres

    Slike9 authored
    Field description in schema: `t.integer :field_name, :type => :array`. 
    Error: "undefined method `gsub' for 1:Fixnum" in PostgreSQLColumn#quote_and_escape.
This page is out of date. Refresh to see the latest.
View
11 activerecord/lib/active_record/connection_adapters/postgresql/cast.rb
@@ -69,15 +69,16 @@ def json_to_string(object)
def array_to_string(value, column, adapter, should_be_quoted = false)
casted_values = value.map do |val|
- if String === val
if val == "NULL"
"\"#{val}\""
else
- quote_and_escape(adapter.type_cast(val, column, true))
+ casted_value = adapter.type_cast(val, column, true)
+ if String === casted_value
+ quote_and_escape(casted_value)
+ else
+ casted_value
+ end
end
- else
- adapter.type_cast(val, column, true)
- end
end
"{#{casted_values.join(',')}}"
end
Something went wrong with that request. Please try again.