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.

Reading FETCH FIRST WITH TIESdoctest
$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']
Refusing a count that would need parenthesesdoctest
$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\InvalidConstruction

Properties§

public Scalar|null $count = null
public bool $withTies = false

Methods§

public function __construct(public Scalar|null $count = null, public bool $withTies = false)

Parameters

$countScalar|nullThe row count; null for one row
$withTiesboolWhether rows that tie with the last row are returned too
Calls 3
public function render(Output $out): void

Writes FETCH FIRST, the count, ROWS and ONLY or WITH TIES.

Parameters

$outOutput
Calls 1

Test cases 1§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 1

Relations§

Instantiated in 1
Type checks 2
Type declarations 3