<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -2055,9 +2055,10 @@ module ActiveRecord #:nodoc:
         end
 
         def replace_named_bind_variables(statement, bind_vars) #:nodoc:
-          statement.gsub(/:([a-zA-Z]\w*)/) do
-            match = $1.to_sym
-            if bind_vars.include?(match)
+          statement.gsub(/(:?):([a-zA-Z]\w*)/) do
+            if $1 == ':' # skip postgresql casts
+              $&amp; # return the whole match
+            elsif bind_vars.include?(match = $2.to_sym)
               quote_bound_value(bind_vars[match])
             else
               raise PreparedStatementInvalid, &quot;missing value for :#{match} in #{statement}&quot;</diff>
      <filename>activerecord/lib/active_record/base.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,6 @@
 require &quot;cases/helper&quot;
 require 'models/author'
+require 'models/categorization'
 require 'models/comment'
 require 'models/company'
 require 'models/topic'
@@ -394,6 +395,12 @@ class FinderTest &lt; ActiveRecord::TestCase
     assert_equal '1,1,1', bind('?', os)
   end
 
+  def test_named_bind_with_postgresql_type_casts
+    l = Proc.new { bind(&quot;:a::integer '2009-01-01'::date&quot;, :a =&gt; '10') }
+    assert_nothing_raised(&amp;l)
+    assert_equal &quot;#{ActiveRecord::Base.quote_value('10')}::integer '2009-01-01'::date&quot;, l.call
+  end
+
   def test_string_sanitation
     assert_not_equal &quot;#{ActiveRecord::Base.connection.quoted_string_prefix}'something ' 1=1'&quot;, ActiveRecord::Base.sanitize(&quot;something ' 1=1&quot;)
     assert_equal &quot;#{ActiveRecord::Base.connection.quoted_string_prefix}'something; select table'&quot;, ActiveRecord::Base.sanitize(&quot;something; select table&quot;)</diff>
      <filename>activerecord/test/cases/finder_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>2e1b56c93745bf0513e449e95830edd390abfaf2</id>
    </parent>
  </parents>
  <author>
    <name>Tarmo T&#228;nav</name>
    <email>tarmo@itech.ee</email>
  </author>
  <url>http://github.com/rails/rails/commit/509374ebe2dba0dc2ea7e44d67a6f8d530d12fac</url>
  <id>509374ebe2dba0dc2ea7e44d67a6f8d530d12fac</id>
  <committed-date>2008-06-22T16:16:06-07:00</committed-date>
  <authored-date>2008-05-12T07:58:03-07:00</authored-date>
  <message>Named bind variables can now be used with postgresql-style typecasts

For example :conditions =&gt; ['stringcol::integer = :var', { :var =&gt; 10 }]
will no longer raise an exception about ':integer' having a missing value.</message>
  <tree>6ee9f77d5f0d21c3921d0de8cf5c23bc4e0fe133</tree>
  <committer>
    <name>Jeremy Kemper</name>
    <email>jeremy@bitsweat.net</email>
  </committer>
</commit>
