cake/join

Functions to build JOIN clauses of SQL queries.

Tables, views and sub-queries can be joined together.

Supported join kinds

You can also build following joins using the provided query builder functions:

Types

pub type Join =
  read_query.Join
pub type JoinTarget =
  read_query.JoinTarget
pub type ReadQuery =
  read_query.ReadQuery
pub type Where =
  read_query.Where

Functions

pub fn cross(with wth: JoinTarget, alias als: String) -> Join

Creates a CROSS JOIN.

Also called cartesian product.

pub fn cross_lateral(
  with wth: JoinTarget,
  alias als: String,
) -> Join

Creates a CROSS JOIN LATERAL.

⚠️⚠️⚠️

CAUTION: LATERAL joins are not optimized by the query planner, and can be very slow on large datasets, especially when the sub-query returns many rows.

⚠️⚠️⚠️

See https://www.postgresql.org/docs/9.3/sql-select.html#SQL-FROM for an explanation on how LATERAL works.

NOTICE: LATERAL is supported by 🐘PostgreSQL 9.3+ and recent 🐬MySQL versions.

pub fn full(
  with wth: JoinTarget,
  on on: Where,
  alias als: String,
) -> Join

Creates a FULL JOIN.

Also called FULL OUTER JOIN.

Inclusive by default.

Set on to WHERE a.key IS NULL OR b.key IS NULL to make it exclusive.

pub fn inner(
  with wth: JoinTarget,
  on on: Where,
  alias als: String,
) -> Join

Create an INNER JOIN.

pub fn inner_lateral(
  with wth: JoinTarget,
  alias als: String,
) -> Join

Creates a INNER JOIN LATERAL ... ON TRUE.

⚠️⚠️⚠️

CAUTION: LATERAL joins are not optimized by the query planner, and can be very slow on large datasets, especially when the sub-query returns many rows.

⚠️⚠️⚠️

See https://www.postgresql.org/docs/9.3/sql-select.html#SQL-FROM for an explanation on how LATERAL works.

Any filtering must be done in WHERE clauses as the JOIN ON clause is always TRUE when calling this function.

NOTICE: LATERAL is supported by 🐘PostgreSQL 9.3+ and recent 🐬MySQL versions.

pub fn left(
  with wth: JoinTarget,
  on on: Where,
  alias als: String,
) -> Join

Creates a LEFT JOIN.

Also called LEFT OUTER JOIN.

Inclusive by default.

Set on to WHERE a.key IS NULL to make it exclusive.

pub fn left_lateral(
  with wth: JoinTarget,
  alias als: String,
) -> Join

Creates a LEFT JOIN LATERAL ... ON TRUE.

⚠️⚠️⚠️

CAUTION: LATERAL joins are not optimized by the query planner, and can be very slow on large datasets, especially when the sub-query returns many rows.

⚠️⚠️⚠️

See https://www.postgresql.org/docs/9.3/sql-select.html#SQL-FROM for an explanation on how LATERAL works.

Any filtering must be done in WHERE clauses as the JOIN ON clause is always TRUE when calling this function.

NOTICE: LATERAL is supported by 🐘PostgreSQL 9.3+ and recent 🐬MySQL versions.

pub fn right(
  with wth: JoinTarget,
  on on: Where,
  alias als: String,
) -> Join

Creates a RIGHT JOIN.

Also called RIGHT OUTER JOIN.

Inclusive by default.

Set on to WHERE b.key IS NULL to make it exclusive.

pub fn sub_query(sub_query sq: ReadQuery) -> JoinTarget

Create a JOIN target from a sub-query.

pub fn table(table_name tbl_nm: String) -> JoinTarget

Create a JOIN target from a table name.

Search Document