0 follower

Final Class Yiisoft\Db\Expression\Value\ArrayValue

InheritanceYiisoft\Db\Expression\Value\ArrayValue
ImplementsYiisoft\Db\Expression\ExpressionInterface

Represents an array SQL expression.

Expressions of this type can be used in conditions as well:

$query->andWhere(['@>', 'items', new ArrayValue([1, 2, 3], 'integer[]')]);

Which, depending on DBMS, will result in a well-prepared condition. For example, in PostgresSQL it will be compiled to WHERE "items" @> ARRAY[1, 2, 3]::integer[].

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Yiisoft\Db\Expression\Value\ArrayValue

Property Details

Method Details

Hide inherited methods

__construct() public method

public __construct( iterable|Yiisoft\Db\Schema\Data\LazyArrayInterface|Yiisoft\Db\Query\QueryInterface|string|null $value, Yiisoft\Db\Schema\Column\ColumnInterface|string|null $type null ): mixed
$value iterable|Yiisoft\Db\Schema\Data\LazyArrayInterface|Yiisoft\Db\Query\QueryInterface|string|null

The array value which can be represented as

$type Yiisoft\Db\Schema\Column\ColumnInterface|string|null

The array column type which can be represented as

String type will be converted into Yiisoft\Db\Schema\Column\ColumnInterface using Yiisoft\Db\Schema\Column\ColumnFactoryInterface::fromDefinition(). The column type is used to typecast array values before saving into the database and for adding type hint to the SQL statement. If the type isn't specified and DBMS can't guess it from the context, SQL error will be raised. The Yiisoft\Db\QueryBuilder\ColumnDefinitionBuilderInterface::buildType() method will be invoked to convert Yiisoft\Db\Schema\Column\ColumnInterface into SQL representation. For example, it will convert string[] to varchar(255)[] (for PostgresSQL). The preferred way is to use \Yiisoft\Db\Expression\Value\ColumnBuilder to generate the column type as an instance of Yiisoft\Db\Schema\Column\ColumnInterface.

                public function __construct(
    public readonly iterable|LazyArrayInterface|QueryInterface|string|null $value,
    public readonly ColumnInterface|string|null $type = null,
) {}