Path: | lib/sequel/extensions/pg_array_ops.rb |
Last Update: | Fri Jul 13 14:52:09 +0000 2012 |
The pg_array_ops extension adds support to Sequel‘s DSL to make it easier to call PostgreSQL array functions and operators. The most common usage is taking an object that represents an SQL identifier (such as a :symbol), and calling pg_array on it:
ia = :int_array_column.pg_array
This creates a Sequel::Postgres::ArrayOp object that can be used for easier querying:
ia[1] # int_array_column[1] ia[1][2] # int_array_column[1][2] ia.contains(:other_int_array_column) # @> ia.contained_by(:other_int_array_column) # <@ ia.overlaps(:other_int_array_column) # && ia.concat(:other_int_array_column) # || ia.push(1) # int_array_column || 1 ia.unshift(1) # 1 || int_array_column ia.any # ANY(int_array_column) ia.all # ALL(int_array_column) ia.dims # array_dims(int_array_column) ia.length # array_length(int_array_column, 1) ia.length(2) # array_length(int_array_column, 2) ia.lower # array_lower(int_array_column, 1) ia.lower(2) # array_lower(int_array_column, 2) ia.join # array_to_string(int_array_column, '', NULL) ia.join(':') # array_to_string(int_array_column, ':', NULL) ia.join(':', ' ') # array_to_string(int_array_column, ':', ' ') ia.unnest # unnest(int_array_column)
See the PostgreSQL array function and operator documentation for more details on what these functions and operators do.
If you are also using the pg_array extension, you should load it before loading this extension. Doing so will allow you to use PGArray#op to get an ArrayOp, allowing you to perform array operations on array literals.