Rails 5 and inet type

Issue #242 closed
Grigorii Lutkov
created an issue
  • Mac OS X El Capitan
  • Ruby 2.3.1
  • Rails 5.0.0.rc1
  • pg 0.18.4 or pg 0.19.pre

I have model IpAddress

class IpAddress < ApplicationRecord {
     :id => :integer,
  :value => :inet
}

When I try to update some ip_address object, it validates value for uniqueness with sql query:

IpAddress Exists (19.6ms)  SELECT  1 AS one FROM "ip_addresses" WHERE LOWER("ip_addresses"."value") = LOWER($1) AND ("ip_addresses"."id" != $2) LIMIT $3  [["value", "::1/128"], ["id", 1], ["LIMIT", 1]]
   (0.4ms)  ROLLBACK
Completed 500 Internal Server Error in 697ms (ActiveRecord: 80.2ms)
ActiveRecord::StatementInvalid (PG::UndefinedFunction: ERROR:  function lower(inet) does not exist
LINE 1: SELECT  1 AS one FROM "ip_addresses" WHERE LOWER("ip_address...
                                                   ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
: SELECT  1 AS one FROM "ip_addresses" WHERE LOWER("ip_addresses"."value") = LOWER($1) AND ("ip_addresses"."id" != $2) LIMIT $3):

With Rails 4.2.6 sql query looks like this and working without problems:

IpAddress Exists (0.7ms)  SELECT  1 AS one FROM "ip_addresses" WHERE ("ip_addresses"."value" = '::1/128' AND "ip_addresses"."id" != 1) LIMIT 1

Comments (5)

  1. Log in to comment