classFetchFirst
final class FetchFirst
implements Node
uses Snapshot
Public API: explicitly declared with
@visibility public.FETCH FIRST count ROWS ONLY or WITH TIES: the SQL-standard row limit.
Mirrors PostgreSQL's limitCount with LimitOption COUNT or WITH_TIES. Without a count one row is returned. FIRST and NEXT, and ROW and ROWS, are noise words. The count is a primary expression or a signed numeric constant, as the grammar requires. Source: https://www.postgresql.org/docs/17/sql-select.html#SQL-LIMIT.
$query = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SELECT 1 ORDER BY 1 FETCH NEXT 2 ROW WITH TIES');
[$query->statement->options->limit->count->withTies, $query->toString()] // => [true, 'SELECT 1 ORDER BY 1 FETCH FIRST 2 ROWS WITH TIES']$one = new \SqlSemantics\Platform\PostgreSql\Statement\Literal\Constant(new \SqlSemantics\Platform\PostgreSql\Statement\Literal\IntegerConstant('1'));
$two = new \SqlSemantics\Platform\PostgreSql\Statement\Literal\Constant(new \SqlSemantics\Platform\PostgreSql\Statement\Literal\IntegerConstant('2'));
new \SqlSemantics\Platform\PostgreSql\Statement\Query\Limit\FetchFirst(new \SqlSemantics\Platform\PostgreSql\Statement\Expression\BinaryOperation(new \SqlSemantics\Platform\PostgreSql\Statement\Name\OperatorName(new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('+')), $one, $two)) // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\InvalidConstructionProperties§
public Scalar|null $count = nullpublic bool $withTies = falseMethods§
public function __construct(public Scalar|null $count = null, public bool $withTies = false)Parameters
$count | Scalar|null | The row count; null for one row |
$withTies | bool | Whether rows that tie with the last row are returned too |
Calls 3
- static-call Check::input() line 42
- method-call FetchCounts::admits() line 42
- new FetchCounts line 42
public function render(Output $out): voidWrites FETCH FIRST, the count, ROWS and ONLY or WITH TIES.
Parameters
$out | Output |
Calls 1
- method-call Output::keyword() line 50
Test cases 1§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 1
FetchFirstTestcalls
Relations§
Instantiated in 1
Type checks 2
Type declarations 3
- type SqlSemantics\Platform\PostgreSql\Lowering\Query\LimitRule packages/sql-semantics-postgres/src/Lowering/Query/LimitRule.php:84
- type SqlSemantics\Platform\PostgreSql\Lowering\Query\LimitRule packages/sql-semantics-postgres/src/Lowering/Query/LimitRule.php:102
- type SqlSemantics\Platform\PostgreSql\Statement\Query\Limit\RowLimit packages/sql-semantics-postgres/src/Statement/Query/Limit/RowLimit.php:37