classExtract
final class Extract
implements Scalar, OutputNaming
uses Snapshot
@visibility public.EXTRACT (field FROM source): a field of a date/time or interval value.
The server calls pg_catalog.extract('field', source). The field is written as a reserved keyword, an identifier or a string constant, and the three spellings are distinct token sequences, so the model keeps which was written. Rule: PG-EXTRACT-001. Facts: those of the call (PG-CALL-RESULT-001; numeric for every date/time source type). The result column is named extract. An identifier field is written quoted when it is spelled like a keyword, because the grammar takes only an identifier there. Source: https://www.postgresql.org/docs/17/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT. Status: Implemented.
$extract = new \SqlSemantics\Platform\PostgreSql\Statement\Invocation\Text\Extract(new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('epoch'), new \SqlSemantics\Platform\PostgreSql\Statement\Literal\NullLiteral());
[$extract->fieldName(), $extract->outputName()->value] // => ['epoch', 'extract']Properties§
public ExtractUnit|Name|StringConstant $fieldpublic Scalar $sourceMethods§
public function __construct(
public ExtractUnit|Name|StringConstant $field,
public Scalar $source,
)Parameters
$field | ExtractUnit|Name|StringConstant | The field: a keyword, an identifier or a string constant |
$source | Scalar | The value the field is taken from |
public function fieldName(): stringAnswers the field name the server passes to extract.
Returns
stringTest cases 1
public function outputName(): NameNames an unaliased result column after the function the server calls.
Returns
Test cases 1
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the source and the result of pg_catalog.extract.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 7
- method-call Derivation::scalar() line 77
- method-call CallTyping::catalog() line 79
- new CallTyping line 79
- new ScalarFact line 79
- new Known line 79
- class-const Builtin::Unknown() line 79
- class-const Nullability::NotNull() line 79
public function render(Output $out): voidWrites EXTRACT with the field and the source.
Parameters
$out | Output |
Test cases 2
Calls 4
- method-call Output::keyword() line 87
- method-call Output::node() line 91
- method-call Output::name() line 93
- class-const NameUse::Identifier() line 93
Test cases 6§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 6
ExtractTest::testDeriveScalarDependsForAnAmbiguousSourcecallsExtractTest::testDeriveScalarIsNumericForADatecallsExtractTest::testFieldNameAnswersTheFieldPassedcallsExtractTest::testOutputNameIsExtractcallsExtractTest::testRenderQuotesAnIdentifierSpelledLikeAKeywordcallsExtractTest::testRenderWritesAPlainIdentifierAndAStringcalls