classJsonQueryFunction
final class JsonQueryFunction
implements Scalar, OutputNaming
uses Snapshot
@visibility public.JSON_EXISTS, JSON_QUERY or JSON_VALUE (PostgreSQL 17): a JSON path applied to a value.
Mirrors PostgreSQL's JsonFuncExpr. JSON_EXISTS takes no RETURNING, wrapper, quotes or ON EMPTY; JSON_VALUE takes no wrapper or quotes. Rule: PG-JSON-QUERY-001. Facts: the RETURNING type, otherwise boolean, jsonb or text; the result may be NULL. Diagnostics: the behaviors and clause combinations the server rejects (PG-JSON-CHECKS-001). The result column is named after the function in lower case. Source: https://www.postgresql.org/docs/17/functions-json.html#FUNCTIONS-SQLJSON-QUERYING. Status: Implemented.
$exists = new \SqlSemantics\Platform\PostgreSql\Statement\Invocation\Json\Query\JsonQueryFunction(
\SqlSemantics\Platform\PostgreSql\Statement\Invocation\Json\Query\JsonFunctionKind::Exists,
new \SqlSemantics\Platform\PostgreSql\Statement\Invocation\Json\JsonValueExpression(new \SqlSemantics\Platform\PostgreSql\Statement\Literal\NullLiteral()),
new \SqlSemantics\Platform\PostgreSql\Statement\Literal\Constant(new \SqlSemantics\Platform\PostgreSql\Statement\Literal\StringConstant('$.a')),
);
$exists->outputName()->value // => 'json_exists'Properties§
public list<JsonArgument> $passingpublic JsonFunctionKind $kindpublic JsonValueExpression $contextpublic Scalar $pathpublic JsonReturning|null $returning = nullpublic JsonWrapping|null $wrapper = nullpublic JsonQuoting|null $quotes = nullpublic JsonBehaviorClause|null $behavior = nullMethods§
public function __construct(
public JsonFunctionKind $kind,
public JsonValueExpression $context,
public Scalar $path,
list<JsonArgument> $passing = [],
public JsonReturning|null $returning = null,
public JsonWrapping|null $wrapper = null,
public JsonQuoting|null $quotes = null,
public JsonBehaviorClause|null $behavior = null,
)Parameters
$kind | JsonFunctionKind | The function |
$context | JsonValueExpression | The JSON value the path applies to |
$path | Scalar | The JSON path |
$passing | list<JsonArgument> | The path variables passed |
$returning | JsonReturning|null | The RETURNING clause |
$wrapper | JsonWrapping|null | The wrapper clause of JSON_QUERY |
$quotes | JsonQuoting|null | The quotes clause of JSON_QUERY |
$behavior | JsonBehaviorClause|null | The ON EMPTY and ON ERROR behaviors |
Calls 7
- static-call Check::listOf() line 72
- class-const JsonArgument::class() line 72
- static-call Check::input() line 73
- class-const JsonFunctionKind::Query() line 73
- class-const JsonFunctionKind::Exists() line 74
- method-call Precedence::takesUniqueness() line 75
- new Precedence line 75
public function outputName(): NameNames an unaliased result column after the function.
Returns
Test cases 1
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the operands and clauses, reports rejected combinations, and derives the result.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 8
- method-call JsonValueExpression::deriveValue() line 91
- method-call Derivation::scalar() line 92
- method-call JsonChecks::query() line 98
- new JsonChecks line 98
- new Known line 99
- method-call JsonFunctionKind::builtin() line 99
- new ScalarFact line 101
- class-const Nullability::Nullable() line 101
public function render(Output $out): voidWrites the function with its clauses in the order of the grammar.
Parameters
$out | Output |
Test cases 1
Calls 2
- method-call Output::keyword() line 109
- method-call Output::node() line 113
Test cases 8§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 7
JsonQueryFunctionTest::testDeriveScalarIsTheReturningTypecallsJsonQueryFunctionTest::testDeriveScalarReportsAnInvalidBehaviorcallsJsonQueryFunctionTest::testOutputNameIsTheFunctioncallsJsonQueryFunctionTest::testRejectsAPathThatWouldTakeTheWrappercallsJsonQueryFunctionTest::testRejectsAWrapperOutsideJsonQuerycallsJsonQueryFunctionTest::testRejectsReturningOnJsonExistscallsJsonQueryFunctionTest::testRenderWritesEveryClauseInOrdercalls
Other tests reaching this symbol 1
Relations§
Instantiated in 3
- new SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonQueryRule::function() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonQueryRule.php:99
- new SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonQueryRule::function() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonQueryRule.php:109
- new SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonQueryRule::function() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonQueryRule.php:119