packages/sql-semantics-postgres/src/Statement/Expression/CastSpelling.php

1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Platform\PostgreSql\Statement\Expression;
6
7/**
8 * How a type cast is written.
9 *
10 * `x::t` and `CAST(x AS t)` request the same conversion; the grammar keeps
11 * them as different token sequences, and only the operator form takes part in
12 * operator precedence.
13 * Source: https://www.postgresql.org/docs/17/sql-expressions.html#SQL-SYNTAX-TYPE-CASTS.
14 *
15 * @visibility public
16 * @example Reading the spelling of a cast
17 *     $query = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SELECT 1::text');
18 *     $query->field(0)->expression->spelling // => \SqlSemantics\Platform\PostgreSql\Statement\Expression\CastSpelling::Operator
19 */
20enum CastSpelling
21{
22    /**
23     * The postfix operator `::`.
24     */
25    case Operator;
26
27    /**
28     * The function-like form `CAST ( x AS t )`.
29     */
30    case Function;
31}
32