You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: Incorrect type inference for varchar column as UUID in where query with JRuby JDBC adapter #1197
I've encountered an error when using the JRuby JDBC adapter for PostgreSQL. It seems ActiveRecord incorrectly infers the data type of string values as uuid if its format resembles a UUID,. This happens even if the corresponding database column is explicitly defined as character varying (varchar).
Steps to Reproduce
The following standalone script reliably reproduces the issue.
# frozen_string_literal: truerequire'bundler/inline'gemfiledosource'https://rubygems.org'gem'activerecord','~> 7.1.5.2'gem'activerecord-jdbcpostgresql-adapter','~> 71.0'gem'jruby-openssl'endrequire'active_record'require'logger'# 1. Database Configurationdb_config={adapter: 'jdbcpostgresql',host: 'localhost',database: ENV['db_database'],username: ENV['db_username'],password: ENV['db_password']}ActiveRecord::Base.establish_connection(db_config)ActiveRecord::Base.logger=Logger.new(STDOUT)# 2. Schema and ModelActiveRecord::Schema.definedodrop_table:items,if_exists: truecreate_table:itemsdo |t|
t.string:external_id,limit: 36# Explicitly character varyingt.string:nameendendclassItem < ActiveRecord::Baseend# 3. Seed DataItem.create!(external_id: 'a068351235251000f07fa89bcaf80000',name: 'Existing Item 1')Item.create!(external_id: 'e2d08afc53614c37b32b31270bb8bee3',name: 'Existing Item 2')# 4. Reproduce the Bugids_to_include=[{id: 'a068351235251000f07fa89bcaf80000'},{id: 'a068351235251000f07fa89bcaf80002'}].map{ |item| item[:id]}puts"\n--- DEMONSTRATING THE BUG ---"begin# This query fails due to incorrect type inferencefailing_query=Item.where(external_id: ids_to_include)failing_query.to_aputs"✅ SUCCESS (NO BUG): The query worked unexpectedly."rescueActiveRecord::StatementInvalid=>eputs"❌ FAILURE (BUG REPRODUCED): The query failed as expected."puts" Error Class: #{e.class}"puts" Error Message: #{e.message}"endputs"\n--> Script finished."
Expected Behavior
The query Item.where(workday_style_id: ids_to_include) should execute successfully. It should generate a SQL query where the bind parameters for the IN clause are treated as strings (varchar), matching the column type.
Actual Behavior
However, the query fails with an ActiveRecord::StatementInvalid exception. The underlying PostgreSQL error is PG::UndefinedFunction: ERROR: operator does not exist: character varying <> uuid.
This indicates that the adapter sent the string parameters to the database typed as uuid instead of varchar.
changed the title [-]Bug: Incorrect type inference for varchar column as UUID in .where query with JRuby JDBC adapter[/-][+]Bug: Incorrect type inference for varchar column as UUID in where query with JRuby JDBC adapter[/+]on Sep 3, 2025
Activity
[-]Bug: Incorrect type inference for varchar column as UUID in .where query with JRuby JDBC adapter[/-][+]Bug: Incorrect type inference for varchar column as UUID in where query with JRuby JDBC adapter[/+]JesseChavez commentedon Dec 13, 2025
Hi @ubinexy-tw
I might fixed this issue a while back in my fork and I created a PR to port the fix to upstream
potential fix in my fork
JesseChavez@b715a76
PR to port the change
#1206
Remove UUID type guessing for untyped string binds