Selecto.Advanced.ArrayOperations
(Selecto v0.4.5)
Copy Markdown
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
# 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")
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.
Functions
Create an array containment/testing operation for filters.
Examples
# Array contains
create_array_filter(:array_contains, "tags", ["featured", "new"])
# Array overlap
create_array_filter(:array_overlap, "categories", ["electronics", "computers"])
Create an array aggregation operation specification.
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")
Create an array length/dimension operation.
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")
Create an unnest operation for array expansion.
Examples
# Unnest array column
create_unnest("special_features", as: "feature")
# Unnest with ordinality
create_unnest("tags", with_ordinality: true, as: "tag")
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.