Skip to content

Commit 89827d2

Browse files
committed
Postgres, fix test only check for insensitive comparison capability once
8) Failure: ActiveRecord::ConnectionAdapters::PostgreSQLAdapterTest#test_only_check_for_insensitive_comparison_capability_once [test/cases/adapters/postgresql/postgresql_adapter_test.rb:539]: 1 instead of 0 queries were executed. Queries: SELECT exists( SELECT * FROM pg_proc WHERE proname = 'lower' AND proargtypes = ARRAY['example_type'::regtype]::oidvector ) OR exists( SELECT * FROM pg_proc INNER JOIN pg_cast ON ARRAY[casttarget]::oidvector = proargtypes WHERE proname = 'lower' AND castsource = 'example_type'::regtype ) . Expected: 0 Actual: 1
1 parent 083f649 commit 89827d2

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

lib/arjdbc/postgresql/adapter.rb

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -667,22 +667,27 @@ def arel_visitor
667667

668668
# Pulled from ActiveRecord's Postgres adapter and modified to use execute
669669
def can_perform_case_insensitive_comparison_for?(column)
670-
@case_insensitive_cache ||= {}
671-
@case_insensitive_cache[column.sql_type] ||= begin
672-
sql = <<~SQL
673-
SELECT exists(
674-
SELECT * FROM pg_proc
675-
WHERE proname = 'lower'
676-
AND proargtypes = ARRAY[#{quote column.sql_type}::regtype]::oidvector
677-
) OR exists(
678-
SELECT * FROM pg_proc
679-
INNER JOIN pg_cast
680-
ON ARRAY[casttarget]::oidvector = proargtypes
681-
WHERE proname = 'lower'
682-
AND castsource = #{quote column.sql_type}::regtype
683-
)
684-
SQL
685-
select_value(sql, 'SCHEMA')
670+
# NOTE: citext is an exception. It is possible to perform a
671+
# case-insensitive comparison using `LOWER()`, but it is
672+
# unnecessary, as `citext` is case-insensitive by definition.
673+
@case_insensitive_cache ||= { "citext" => false }
674+
@case_insensitive_cache.fetch(column.sql_type) do
675+
@case_insensitive_cache[column.sql_type] = begin
676+
sql = <<~SQL
677+
SELECT exists(
678+
SELECT * FROM pg_proc
679+
WHERE proname = 'lower'
680+
AND proargtypes = ARRAY[#{quote column.sql_type}::regtype]::oidvector
681+
) OR exists(
682+
SELECT * FROM pg_proc
683+
INNER JOIN pg_cast
684+
ON ARRAY[casttarget]::oidvector = proargtypes
685+
WHERE proname = 'lower'
686+
AND castsource = #{quote column.sql_type}::regtype
687+
)
688+
SQL
689+
select_value(sql, 'SCHEMA')
690+
end
686691
end
687692
end
688693

0 commit comments

Comments
 (0)