Module: Sequel::Postgres::AutoParameterizeInArray

Defined in:
lib/sequel/extensions/pg_auto_parameterize_in_array.rb

Overview

Enable automatically parameterizing queries.

Defined Under Namespace

Modules: TreatStringListAsTextArray, TreatStringListAsUntypedArray

Instance Method Summary collapse

Instance Method Details

#complex_expression_sql_append(sql, op, args) ⇒ Object

Transform column IN (…) expressions into column = ANY($) and column NOT IN (…) expressions into column != ALL($) using an array bound variable for the ANY/ALL argument, if all values inside the predicate are of the same type and the type is handled by the extension. This is the same optimization PostgreSQL performs internally, but this reduces the number of bound variables.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/sequel/extensions/pg_auto_parameterize_in_array.rb', line 99

def complex_expression_sql_append(sql, op, args)
  case op
  when :IN, :"NOT IN"
    l, r = args
    if auto_param?(sql) && (type = _bound_variable_type_for_array(r))
      if op == :IN 
        op = :"="
        func = :ANY
      else
        op = :!=
        func = :ALL
      end
      args = [l, Sequel.function(func, _convert_array_to_pg_array_with_type(r, type))]
    end
  end

  super
end