packages/sql-semantics-postgres/src/Statement/Literal/NoSuchParameter.php
1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Platform\PostgreSql\Statement\Literal;
6
7use SqlSemantics\Platform\PostgreSql\Model\Statement\Fact\Diagnostic;
8use SqlSemantics\Platform\PostgreSql\Model\Statement\Snapshot;
9
10/**
11 * A parameter reference whose number no statement can bind.
12 *
13 * Parameters are numbered from 1; the server reports `$0` and numbers beyond
14 * its limit as undefined parameters.
15 * Source: https://www.postgresql.org/docs/17/sql-expressions.html#SQL-EXPRESSIONS-PARAMETERS-POSITIONAL.
16 *
17 * @visibility public
18 * @example Reporting parameter zero
19 * (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SELECT $0') // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\SemanticException: There is no parameter $0.
20 */
21final class NoSuchParameter implements Diagnostic
22{
23 use Snapshot;
24
25 /**
26 * @param string $marker The parameter marker as the server reads it
27 */
28 public function __construct(public readonly string $marker)
29 {
30 }
31
32 /**
33 * Describes the problem.
34 */
35 public function message(): string
36 {
37 return 'There is no parameter ' . $this->marker . '.';
38 }
39}
40