Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lateral joins #184

Open
wants to merge 2 commits into
base: 3.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/Pgsql/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,37 @@
*/
class Select extends Common\Select
{
/**
*
* Adds a LATERAL JOIN to an aliased subselect and columns to the query.
*
* @param string $join The join type: inner, left, natural, etc.
*
* @param string|Select $spec If a Select
* object, use as the sub-select; if a string, the sub-select
* command string.
*
* @param string $name The alias name for the sub-select.
*
* @param string $cond Join on this condition.
*
* @param array $bind Values to bind to ?-placeholders in the condition.
*
* @return $this
*
* @throws Exception
*
*/
public function lateralJoinSubSelect($join, $spec, $name, $cond = null, array $bind = array())
{
$join = strtoupper(ltrim("$join JOIN LATERAL"));
$this->addTableRef("$join (SELECT ...) AS", $name);

$spec = $this->subSelect($spec, ' ');
$name = $this->quoter->quoteName($name);
$cond = $this->fixJoinCondition($cond, $bind);

$text = rtrim("$join ($spec ) $name $cond");
return $this->addJoin(' ' . $text);
}
}