classSelectOptions
final class SelectOptions
implements Node
uses Snapshot
Public API: explicitly declared with
@visibility public.The ORDER BY, LIMIT, OFFSET, FETCH and locking clauses written after a query body.
Mirrors the sortClause, limitOffset, limitCount, limitOption and lockingClause that PostgreSQL attaches to a SelectStmt. The locking clauses may be written before or after the limit; the order is kept. FOR READ ONLY requests no lock. An integer constant in ORDER BY is an output position and must be given as one. Source: https://www.postgresql.org/docs/17/sql-select.html.
$query = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SELECT 1 ORDER BY 1 FOR UPDATE LIMIT 1');
[count($query->statement->options->order), $query->statement->options->lockingFirst, $query->toString()] // => [1, true, 'SELECT 1 ORDER BY 1 FOR UPDATE LIMIT 1']new \SqlSemantics\Platform\PostgreSql\Statement\Query\Clause\SelectOptions([new \SqlSemantics\Platform\PostgreSql\Statement\Query\SortItem(new \SqlSemantics\Platform\PostgreSql\Statement\Literal\Constant(new \SqlSemantics\Platform\PostgreSql\Statement\Literal\IntegerConstant('1')))]) // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\InvalidConstructionProperties§
public list<SortItem> $orderpublic list<LockingClause> $lockingpublic RowLimit|null $limit = nullpublic bool $readOnly = falsepublic bool $lockingFirst = falseMethods§
public function __construct(
list<SortItem> $order = [],
public RowLimit|null $limit = null,
list<LockingClause> $locking = [],
public bool $readOnly = false,
public bool $lockingFirst = false,
)Parameters
$order | list<SortItem> | The ORDER BY items in written order |
$limit | RowLimit|null | The LIMIT, FETCH and OFFSET clauses |
$locking | list<LockingClause> | The locking clauses in written order |
$readOnly | bool | Whether FOR READ ONLY is written instead of locking clauses |
$lockingFirst | bool | Whether the locking clauses are written before the limit |
Calls 6
- static-call Check::listOf() line 55
- class-const SortItem::class() line 55
- class-const LockingClause::class() line 56
- static-call Check::input() line 57
- method-call Positions::value() line 61
- new Positions line 61
public function locks(): boolTells whether locking clauses or FOR READ ONLY are written.
Returns
boolTest cases 1
public function render(Output $out): voidWrites ORDER BY, then the limit and the locking clauses in the order written.
Parameters
$out | Output |
Calls 3
- method-call Output::keyword() line 79
- method-call SelectOptions::writeLocking() line 82
- method-call Output::node() line 83
public function writeLocking(Output $out): voidWrites the locking clauses or FOR READ ONLY.
Parameters
$out | Output |
Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Statement\Query\Clause\SelectOptions::render() packages/sql-semantics-postgres/src/Statement/Query/Clause/SelectOptions.php:82
- method-call SqlSemantics\Platform\PostgreSql\Statement\Query\Clause\SelectOptions::render() packages/sql-semantics-postgres/src/Statement/Query/Clause/SelectOptions.php:88
Calls 2
- method-call Output::keyword() line 97
- method-call Output::node() line 100
Test cases 11§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 1
Other tests reaching this symbol 10
CarriersTest::testCarryAddsAnOccurrenceNoNameReachescallsCarriersTest::testCoreUnwrapsParenthesesAndClausescallsCarriersTest::testTakeAnswersTheCarriersOfAQuerycallsCarrierTest::testDeriveRelationAnswersARowWithoutColumnscallsCarrierTest::testRenderWritesNothingcallsQueryExpressionFactsTest::testAnyTellsWhetherAnOptionMatchescallsSelectFactsTest::testLayersPutTheOwnOptionsFirstcallsSelectFactsTest::testLocksTellsALockingLayercallsTrailingTest::testOptionsAnswersTheLastSortExpressionWithoutDirectioncallsTrailingTest::testOptionsAnswersTheLimitOnlyBeforeTheLockingcalls
Relations§
Instantiated in 1
Type declarations 15
- type SqlSemantics\Platform\PostgreSql\Lowering\Query\ClauseRule packages/sql-semantics-postgres/src/Lowering/Query/ClauseRule.php:57
- type SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:162
- type SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:181
- type SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:199
- type SqlSemantics\Platform\PostgreSql\Lowering\Query\SelectRule packages/sql-semantics-postgres/src/Lowering/Query/SelectRule.php:218
- type SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\QueryExpressionFacts::merged() packages/sql-semantics-postgres/src/Rules/Query/Facts/QueryExpressionFacts.php:90
- type SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\QueryExpressionFacts::merged() packages/sql-semantics-postgres/src/Rules/Query/Facts/QueryExpressionFacts.php:91
- type SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\QueryExpressionFacts::merged() packages/sql-semantics-postgres/src/Rules/Query/Facts/QueryExpressionFacts.php:92
- type SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SelectFacts packages/sql-semantics-postgres/src/Rules/Query/Facts/SelectFacts.php:122
- type SqlSemantics\Platform\PostgreSql\Rules\Query\Facts\SelectFacts packages/sql-semantics-postgres/src/Rules/Query/Facts/SelectFacts.php:140
- type SqlSemantics\Platform\PostgreSql\Rules\Query\Limits packages/sql-semantics-postgres/src/Rules/Query/Limits.php:40
- type SqlSemantics\Platform\PostgreSql\Rules\Query\Trailing packages/sql-semantics-postgres/src/Rules/Query/Trailing.php:98
- type SqlSemantics\Platform\PostgreSql\Statement\Query\QueryExpression packages/sql-semantics-postgres/src/Statement/Query/QueryExpression.php:49
- type SqlSemantics\Platform\PostgreSql\Statement\Query\Select packages/sql-semantics-postgres/src/Statement/Query/Select.php:91
- type SqlSemantics\Platform\PostgreSql\Statement\Query\TableQuery packages/sql-semantics-postgres/src/Statement/Query/TableQuery.php:47