validate_uniqueness_of (2.3.5) with scoping broken against PostgreSQL 9.0 #901

lighthouse-import opened this Issue May 16, 2011 · 1 comment


None yet
1 participant

Imported from Lighthouse. Original ticket at:
Created by cschiefelbein - 2011-03-04 20:24:09 UTC

validate_uniqueness_of does not quote scoped values when constructing the SQL query, so if the scoped column happens to be text, you get a PGError. (PostgreSQL 8.2 server did not complain)

class Group < ActiveRecord::Base

  # name, section, and subsection are all text columns
  validates_uniqueness_of :name, :scope => [:section, :subsection]


class GroupTest < ActiveSupport::TestCase
  # blows up with PGError
  should validate_uniqueness_of(:name).scoped_to([:section, :subsection])

Here is the specific error from the database:

ActiveRecord::StatementInvalid: PGError: ERROR:  operator does not exist: character varying = integer
LINE 1: ..."groups"."name" = E'09-01' AND "groups".section = 1 AND "g...
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

I have written a patch against ActiveRecord::Validations (see attached). I would gladly write tests too, but I'm running on Gentoo, which does not know about libxml2-dev or libxslt1-dev, and "gem install bundler" is timing out right now, too. So I don't have a formal test setup (but my patch works in the above case).

This comment has been minimized.

Show comment Hide comment

lighthouse-import May 16, 2011

Attachments saved to Gist:

Attachments saved to Gist:

hisas pushed a commit to hisas/rails that referenced this issue May 9, 2017

Merge pull request #901 from taavo/assign-strings-to-text-html-parts
Allow string assignment for text_part and html_part
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment