classPositionalParameter
final class PositionalParameter
implements Scalar, OutputNaming
uses Snapshot
@visibility public.A positional parameter reference, written $1, $2 and so on.
Rule: PG-PARAMETER-001. Facts: inside a list that declares parameter types (the parameters of a routine with an SQL-standard body, the types of PREPARE) the parameter has the declared type of its position and can be NULL; a number beyond the parameters of a routine is an undefined parameter, a number beyond the types of PREPARE is inferred from its use. Anywhere else the type and NULL fact depend on the value bound to the parameter, which no context declares. $0 and a number above 268435455 are undefined parameters. PostgreSQL 17 rejects a number above 2147483647 while scanning; PostgreSQL 16 converts it with C integer conversion, so there the bound parameter is the number reduced to 32 bits. Source: https://www.postgresql.org/docs/17/sql-expressions.html#SQL-EXPRESSIONS-PARAMETERS-POSITIONAL, https://www.postgresql.org/docs/17/xfunc-sql.html#XFUNC-SQL-FUNCTION-ARGUMENTS, https://www.postgresql.org/docs/17/sql-prepare.html. Status: Implemented.
$query = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SELECT $1');
[$query->statement->targets[0]->expression->number, $query->field(0)->type->missing[0]->describe()] // => ['1', 'the value bound to parameter $1']Properties§
public string $numberMethods§
public function __construct(public string $number)Parameters
$number | string | The parameter number as canonical decimal digits |
Calls 2
- static-call Check::input() line 52
- function-call
preg_matchline 52
public function bound(GrammarRelease $release): ?intAnswers the number of the parameter the server binds under a release, or null when it binds none.
Parameters
$release | GrammarRelease |
Returns
?intTest cases 2
Called from 1
Calls 2
- function-call
strlenline 60 - class-const GrammarRelease::PostgreSql166() line 61
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the declared type of the parameter, facts that depend on the bound value, or the diagnostic of an undefined parameter.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 8
- method-call PositionalParameter::bound() line 82
- new NoSuchParameter line 84
- method-call Derivation::report() line 85
- new ScalarFact line 87
- new Invalid line 87
- class-const Nullability::Dependent() line 87
- new Dependent line 110
- new UnboundParameter line 110
public function render(Output $out): voidWrites the parameter marker.
Parameters
$out | Output |
Test cases 1
Calls 1
- method-call Output::spelled() line 118
Test cases 14§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 9
PositionalParameterTest::testBoundIsTheNumberWithinTheLimitOfTheServercallsPositionalParameterTest::testBoundReducesTheNumberToThirtyTwoBitsInPostgreSql16callsPositionalParameterTest::testDeriveScalarDependsOnTheBoundValuecallsPositionalParameterTest::testDeriveScalarHasTheDeclaredTypeOfItsPositioncallsPositionalParameterTest::testDeriveScalarReportsAParameterARoutineDoesNotDeclarecallsPositionalParameterTest::testDeriveScalarReportsParameterZerocallsPositionalParameterTest::testOutputNameIsNonecallsPositionalParameterTest::testRejectsLeadingZeroscallsPositionalParameterTest::testRenderWritesTheMarkercalls
Other tests reaching this symbol 5
ExpressionsTest::testExpressionsFlattensAnExpressionListcallsPrimaryRuleTest::testParameterWithoutStepsIsTheParametercallsLiteralsTest::testParameterCanonicalizesTheNumbercallsLiteralsTest::testParameterKeepsALargeNumberInPostgreSql16callsIndirectionTest::testOutputNameIsTheLastSelectedFieldcalls