Selecto.Advanced.ArrayOperations (Selecto v0.4.3)

Array operations support for PostgreSQL array functionality.

Provides comprehensive support for array construction, aggregation, manipulation, testing, and unnesting operations. Works with PostgreSQL native array types and provides type-safe operations for array columns.

examples

Examples

# Array aggregation
selecto
|> Selecto.select([
    "category.name",
    {:array_agg, "film.title", as: "films"},
    {:array_length, {:array_agg, "film.film_id"}, 1, as: "film_count"}
  ])
|> Selecto.group_by(["category.category_id", "category.name"])

# Array filtering
selecto
|> Selecto.filter([
    {:array_contains, "film.special_features", ["Trailers"]},
    {:array_overlap, "film.special_features", ["Deleted Scenes", "Behind the Scenes"]}
  ])

# Array unnesting
selecto
|> Selecto.select(["film.title", "feature"])
|> Selecto.unnest("film.special_features", as: "feature")

Link to this section Summary

Functions

Create an array containment/testing operation for filters.

Create an array aggregation operation specification.

Create an array length/dimension operation.

Create an unnest operation for array expansion.

Check if an operation is an aggregation function.

Check if an operation is a filter/WHERE clause operation.

Check if an operation is an unnest operation.

Generate SQL for an array operation.

Validate an array operation specification.

Link to this section Functions

Link to this function

create_array_filter(operation, column, value)

Create an array containment/testing operation for filters.

examples

Examples

# Array contains
create_array_filter(:array_contains, "tags", ["featured", "new"])

# Array overlap
create_array_filter(:array_overlap, "categories", ["electronics", "computers"])
Link to this function

create_array_operation(operation, column, opts \\ [])

Create an array aggregation operation specification.

examples

Examples

# Simple array aggregation
create_array_operation(:array_agg, "film.title", as: "film_titles")

# Array aggregation with DISTINCT
create_array_operation(:array_agg, "actor.name", distinct: true, as: "unique_actors")

# Array aggregation with ORDER BY
create_array_operation(:array_agg, "film.title", 
  order_by: [{"film.release_year", :desc}], 
  as: "films_by_year")
Link to this function

create_array_size(operation, column, dimension \\ nil, opts \\ [])

Create an array length/dimension operation.

examples

Examples

# Get array length at dimension 1
create_array_size(:array_length, "tags", 1, as: "tag_count")

# Get array cardinality (total number of elements)
create_array_size(:cardinality, "matrix", as: "total_elements")
Link to this function

create_unnest(column, opts \\ [])

Create an unnest operation for array expansion.

examples

Examples

# Unnest array column
create_unnest("special_features", as: "feature")

# Unnest with ordinality
create_unnest("tags", with_ordinality: true, as: "tag")
Link to this function

is_aggregate?(spec)

Check if an operation is an aggregation function.

Link to this function

is_filter?(spec)

Check if an operation is a filter/WHERE clause operation.

Link to this function

is_unnest?(arg1)

Check if an operation is an unnest operation.

Link to this function

to_sql(spec, params_list, selecto \\ nil)

Generate SQL for an array operation.

Link to this function

validate_array_operation!(spec)

Validate an array operation specification.