classJsonRule
final class JsonRule
Lowers the SQL/JSON constructors and aggregates and the clauses they share with the query functions.
Rule: PG-JSON-LOWERING-001. Scope: the JSON_OBJECT, JSON_ARRAY, JSON, JSON_SCALAR and JSON_SERIALIZE productions of func_expr_common_subexpr, json_aggregate_func, json_value_expr, json_value_expr_list, json_format_clause, json_format_clause_opt, json_encoding_clause_opt (16), json_returning_clause_opt (17), json_output_clause_opt (16), json_name_and_value_list, json_name_and_value, json_object_constructor_null_clause_opt, json_array_constructor_null_clause_opt, json_array_aggregate_order_by_clause_opt, json_key_uniqueness_constraint_opt. Constructors: the classes of Statement/Invocation/Json and Json/Constructor, and KeywordCall for the legacy JSON_OBJECT with plain arguments. KEYS after WITH or WITHOUT UNIQUE is noise (see InvocationNoise). An encoding other than UTF8, UTF16 or UTF32 is rejected by the grammar's action with an AnalysisException. Termination: lists are flattened iteratively. Source: https://www.postgresql.org/docs/17/functions-json.html#FUNCTIONS-JSON-CREATION-TABLE, https://www.postgresql.org/docs/17/functions-aggregate.html. Status: Implemented.
Methods§
Lowers a JSON constructor production of func_expr_common_subexpr.
Parameters
$form | Form |
Returns
Throws
ImplementationGap When the production has no ruleCalled from 1
Calls 17
- new KeywordCall line 99
- class-const KeywordFunction::JsonObject() line 99
- method-call Form::node() line 99
- new JsonObjectConstructor line 101
- method-call JsonRule::pairs() line 102
- method-call JsonRule::nulls() line 103
- method-call JsonRule::uniqueness() line 104
- method-call JsonRule::returning() line 105
- new JsonArrayConstructor line 109
- method-call JsonRule::values() line 110
- new JsonArrayQuery line 115
- method-call JsonRule::format() line 117
- new JsonParse line 121
- method-call JsonRule::value() line 121
- new JsonScalar line 122
- new JsonSerialize line 123
- static-call ImplementationGap::production() line 124
public function aggregate(
Node $aggregate,
?Scalar $filter,
WindowSpecification|Name|null $over,
): ScalarLowers json_aggregate_func with the FILTER and OVER that follow it.
Parameters
$aggregate | Node | |
$filter | ?Scalar | |
$over | WindowSpecification|Name|null |
Returns
Throws
ImplementationGap When the production has no ruleTest cases 1
Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\CallRule::call() packages/sql-semantics-postgres/src/Lowering/Invocation/CallRule.php:58
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\CallRule::call() packages/sql-semantics-postgres/src/Lowering/Invocation/CallRule.php:65
Calls 9
- new JsonObjectAggregate line 139
- method-call JsonRule::keyValue() line 140
- method-call JsonRule::nulls() line 141
- method-call JsonRule::uniqueness() line 142
- method-call JsonRule::returning() line 143
- new JsonArrayAggregate line 148
- method-call JsonRule::value() line 149
- method-call JsonRule::order() line 150
- static-call ImplementationGap::production() line 156
Lowers json_array_aggregate_order_by_clause_opt.
Parameters
$clause | Node |
Returns
list<SortItem>Throws
ImplementationGap When the production has no ruleTest cases 1
Called from 1
Calls 1
- static-call ImplementationGap::production() line 174
public function value(Node $value): JsonValueExpressionLowers json_value_expr.
Parameters
$value | Node |
Returns
Throws
ImplementationGap When the production has no ruleTest cases 1
Called from 6
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\Invocations::jsonValue() packages/sql-semantics-postgres/src/Lowering/Invocation/Invocations.php:143
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::creation() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:121
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::creation() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:123
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::aggregate() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:149
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::values() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:202
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::keyValue() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:237
Calls 3
- static-call ImplementationGap::production() line 187
- new JsonValueExpression line 190
- method-call JsonRule::format() line 190
public function values(Node $list): list<JsonValueExpression>Lowers json_value_expr_list.
Parameters
$list | Node |
Returns
list<JsonValueExpression>Test cases 1
Called from 1
Calls 2
- method-call Lowering::items() line 201
- method-call JsonRule::value() line 202
Lowers json_name_and_value_list.
Parameters
$list | Node |
Returns
list<JsonPair>Test cases 1
Called from 1
Calls 2
- method-call Lowering::items() line 216
- method-call JsonRule::keyValue() line 217
Lowers json_name_and_value.
Parameters
$pair | Node |
Returns
Throws
ImplementationGap When the production has no ruleTest cases 1
Called from 3
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\Invocations::jsonKeyValue() packages/sql-semantics-postgres/src/Lowering/Invocation/Invocations.php:186
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::aggregate() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:140
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::pairs() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:217
Calls 5
- class-const KeyValueSpelling::Value() line 232
- class-const KeyValueSpelling::Colon() line 233
- static-call ImplementationGap::production() line 234
- new JsonPair line 237
- method-call JsonRule::value() line 237
public function format(Node $format): ?JsonFormatLowers json_format_clause or json_format_clause_opt; no clause is null.
Parameters
$format | Node |
Returns
Throws
AnalysisException When the encoding is not UTF8, UTF16 or UTF32ImplementationGap When the production has no ruleTest cases 2
Called from 5
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\Invocations::jsonFormat() packages/sql-semantics-postgres/src/Lowering/Invocation/Invocations.php:166
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::creation() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:117
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::value() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:190
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::format() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:252
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::returning() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:305
Calls 5
- method-call JsonRule::format() line 252
- new JsonFormat line 253
- method-call JsonRule::encoding() line 254
- method-call JsonRule::encodingClause() line 255
- static-call ImplementationGap::production() line 256
Lowers json_encoding_clause_opt of PostgreSQL 16; no clause is null.
Parameters
$clause | Node |
Returns
?NameThrows
AnalysisException When the encoding is not UTF8, UTF16 or UTF32ImplementationGap When the production has no ruleTest cases 1
Called from 1
Calls 2
- method-call JsonRule::encoding() line 272
- static-call ImplementationGap::production() line 273
Lowers the encoding name of a FORMAT clause.
Parameters
$name | Node |
Returns
Throws
AnalysisException When the encoding is not UTF8, UTF16 or UTF32, which the action of `json_format_clause` in `gram.y` rejects (`makeJsonEncoding` called by `json_encoding_clause_opt` in PostgreSQL 16)Called from 2
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::format() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:254
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::encodingClause() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:272
Calls 2
- static-call JsonEncoding::named() line 285
- new AnalysisException line 286
public function returning(Node $returning): ?JsonReturningLowers json_returning_clause_opt or json_output_clause_opt; no clause is null.
Parameters
$returning | Node |
Returns
Throws
ImplementationGap When the production has no ruleTest cases 1
Called from 9
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\Invocations::jsonReturning() packages/sql-semantics-postgres/src/Lowering/Invocation/Invocations.php:176
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::creation() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:105
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::creation() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:107
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::creation() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:112
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::creation() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:118
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::creation() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:120
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::creation() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:123
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::aggregate() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:143
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::aggregate() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:152
Calls 3
- new JsonReturning line 303
- method-call JsonRule::format() line 305
- static-call ImplementationGap::production() line 307
public function nulls(Node $clause): ?JsonNullHandlingLowers json_object_constructor_null_clause_opt or json_array_constructor_null_clause_opt; no clause is null.
Parameters
$clause | Node |
Returns
Throws
ImplementationGap When the production has no ruleTest cases 1
Called from 5
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\Invocations::jsonNulls() packages/sql-semantics-postgres/src/Lowering/Invocation/Invocations.php:196
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::creation() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:103
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::creation() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:111
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::aggregate() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:141
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::aggregate() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:151
Calls 3
- function-call
array_key_existsline 319 - class-const JsonRule::NULLS() line 319
- static-call ImplementationGap::production() line 320
public function uniqueness(Node $constraint): ?JsonUniqueKeysLowers json_key_uniqueness_constraint_opt; no clause is null.
Parameters
$constraint | Node |
Returns
Throws
ImplementationGap When the production has no ruleTest cases 1
Called from 4
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\Invocations::jsonKeyUniqueness() packages/sql-semantics-postgres/src/Lowering/Invocation/Invocations.php:236
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::creation() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:104
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::creation() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:121
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\JsonRule::aggregate() packages/sql-semantics-postgres/src/Lowering/Invocation/JsonRule.php:142
Calls 4
- function-call
array_key_existsline 334 - class-const JsonRule::UNIQUENESS() line 334
- static-call ImplementationGap::production() line 335
- new JsonUniqueKeys line 339
Private surface 3§
Implementation details, listed for orientation only.
private const NULLS = ['json_object_constructor_null_clause_opt:' => null, 'json_object_constructor_n…private const UNIQUENESS = ['json_key_uniqueness_constraint_opt:' => null, 'json_key_uniqueness_constraint…private Lowering $loweringTest cases 12§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 12
JsonRuleTest::testAggregateLowersTheJsonAggregatescallsJsonRuleTest::testEncodingClauseLowersThePostgreSql16EncodingcallsJsonRuleTest::testEncodingRejectsAnUnknownEncodingcallsJsonRuleTest::testFormatLowersTheEncodingcallsJsonRuleTest::testKeyValueLowersTheColonSpellingcallsJsonRuleTest::testNullsLowersNoClauseToNullcallsJsonRuleTest::testOrderLowersNoOrderingcallsJsonRuleTest::testPairsLowersTheListcallsJsonRuleTest::testReturningLowersNoClauseToNullcallsJsonRuleTest::testUniquenessLowersNoClauseToNullcallsJsonRuleTest::testValueLowersTheFormatcallsJsonRuleTest::testValuesLowersTheListcalls
Relations§
Instantiated in 9
- new SqlSemantics\Platform\PostgreSql\Lowering\Invocation\CallRule::call() packages/sql-semantics-postgres/src/Lowering/Invocation/CallRule.php:58
- new SqlSemantics\Platform\PostgreSql\Lowering\Invocation\CallRule::call() packages/sql-semantics-postgres/src/Lowering/Invocation/CallRule.php:65
- new SqlSemantics\Platform\PostgreSql\Lowering\Invocation\Invocations::jsonValue() packages/sql-semantics-postgres/src/Lowering/Invocation/Invocations.php:143
- new SqlSemantics\Platform\PostgreSql\Lowering\Invocation\Invocations::jsonFormat() packages/sql-semantics-postgres/src/Lowering/Invocation/Invocations.php:166
- new SqlSemantics\Platform\PostgreSql\Lowering\Invocation\Invocations::jsonReturning() packages/sql-semantics-postgres/src/Lowering/Invocation/Invocations.php:176
- new SqlSemantics\Platform\PostgreSql\Lowering\Invocation\Invocations::jsonKeyValue() packages/sql-semantics-postgres/src/Lowering/Invocation/Invocations.php:186
- new SqlSemantics\Platform\PostgreSql\Lowering\Invocation\Invocations::jsonNulls() packages/sql-semantics-postgres/src/Lowering/Invocation/Invocations.php:196
- new SqlSemantics\Platform\PostgreSql\Lowering\Invocation\Invocations::jsonKeyUniqueness() packages/sql-semantics-postgres/src/Lowering/Invocation/Invocations.php:236
- new SqlSemantics\Platform\PostgreSql\Lowering\Invocation\SyntaxRule::subexpression() packages/sql-semantics-postgres/src/Lowering/Invocation/SyntaxRule.php:95
Method calls 9
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\CallRule::call() packages/sql-semantics-postgres/src/Lowering/Invocation/CallRule.php:58
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\CallRule::call() packages/sql-semantics-postgres/src/Lowering/Invocation/CallRule.php:65
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\Invocations::jsonValue() packages/sql-semantics-postgres/src/Lowering/Invocation/Invocations.php:143
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\Invocations::jsonFormat() packages/sql-semantics-postgres/src/Lowering/Invocation/Invocations.php:166
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\Invocations::jsonReturning() packages/sql-semantics-postgres/src/Lowering/Invocation/Invocations.php:176
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\Invocations::jsonKeyValue() packages/sql-semantics-postgres/src/Lowering/Invocation/Invocations.php:186
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\Invocations::jsonNulls() packages/sql-semantics-postgres/src/Lowering/Invocation/Invocations.php:196
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\Invocations::jsonKeyUniqueness() packages/sql-semantics-postgres/src/Lowering/Invocation/Invocations.php:236
- method-call SqlSemantics\Platform\PostgreSql\Lowering\Invocation\SyntaxRule::subexpression() packages/sql-semantics-postgres/src/Lowering/Invocation/SyntaxRule.php:95