The pg_auto_parameterize_in_array extension builds on the pg_auto_parameterize extension, adding support for handling additional types when converting from IN to = ANY and NOT IN to != ALL:
DB[:table].where(column: [1.0, 2.0, ...]) # Without extension: column IN ($1::numeric, $2:numeric, ...) # bound variables: 1.0, 2.0, ... # With extension: column = ANY($1::numeric[]) # bound variables: [1.0, 2.0, ...]
This prevents the use of an unbounded number of bound variables based on the size of the array, as well as using different SQL for different array sizes.
The following types are supported when doing the conversions, with the database type used:
Float |
if any are infinite or NaN, double precision, otherwise numeric |
BigDecimal |
numeric |
Date |
date |
Time |
timestamp (or timestamptz if pg_timestamptz extension is used) |
DateTime |
timestamp (or timestamptz if pg_timestamptz extension is used) |
Sequel::SQLTime |
time |
Sequel::SQL::Blob |
bytea |
String
values are also supported using the text
type, but only if the :treat_string_list_as_text_array
Database option is used. This is because treating strings as text can break programs, since the type for literal strings in PostgreSQL is unknown
, not text
.
The conversion is only done for single dimensional arrays that have more than two elements, where all elements are of the same class (other than nil values).
Related module: Sequel::Postgres::AutoParameterizeInArray