Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveRecord does not serialize arrays for native Postgres array type columns #12261

Closed
tadast opened this issue Sep 17, 2013 · 1 comment
Closed
Assignees
Milestone

Comments

@tadast
Copy link
Contributor

tadast commented Sep 17, 2013

The issue occurs when using #update_column, #update_columns and #update_all on a column of native postgres array type.

SomeTable.first.update_column(:array_column, ['value_1', 'value_2'])
>> UPDATE "some_tables" SET "array_column" = 'value_1','value_2'...

I think the issue is here where the value is passed in to the method with no information about the column type and therefore postgres specific quoting can not be invoked.

If my thinking is correct I can try to fix this

@senny
Copy link
Member

senny commented Sep 27, 2013

I can reproduce this problem on master => https://gist.github.com/senny/6725398

Please do submit a PR to fix the issue.

tadast added a commit to tadast/rails that referenced this issue Sep 28, 2013
tadast added a commit to tadast/rails that referenced this issue Oct 2, 2013
carlosantoniodasilva pushed a commit to carlosantoniodasilva/rails that referenced this issue Dec 20, 2013
…te methods.

Fixes rails#12261. Closes rails#12395.

Conflicts:
	activerecord/test/cases/adapters/postgresql/array_test.rb
	activerecord/test/cases/adapters/postgresql/hstore_test.rb
	activerecord/test/cases/adapters/postgresql/json_test.rb
carlosantoniodasilva added a commit that referenced this issue Dec 23, 2013
This is a combination of 3 commits:

--- 5651009

Do not consider PG array columns as number or text columns

The code uses these checks in several places to know what to do with a
particular column, for instance AR attribute query methods has a branch
like this:

    if column.number?
      !value.zero?
    end

This should never be true for array columns, since it would be the same
as running [].zero?, which results in a NoMethodError exception.

Fixing this by ensuring that array columns in PostgreSQL never return
true for number?/text? checks.

Since most of the array support was based on the postgres_ext lib, it's
worth noting it does the same thing for numeric array columns too:

https://github.com/dockyard/postgres_ext/blob/v1.0.0/lib/postgres_ext/active_record/connection_adapters/postgres_adapter.rb#L72

This extended the same logic for text columns to ensure consistency.

--- 73bba4c

Serialize postgres' hstore, json and array types correctly in AR update methods.

Fixes #12261. Closes #12395.

--- 9e1740a

Tidy up fix for PG extensions quoting

Always pass in the column for quote_bound_value and quote using it in
case it exists there.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants