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 mixed __construct ( iterable|Yiisoft\Db\Schema\Data\LazyArrayInterface|Yiisoft\Db\Query\QueryInterface|string|null $value, Yiisoft\Db\Schema\Column\ColumnInterface|string|null $type null )
$value iterable|Yiisoft\Db\Schema\Data\LazyArrayInterface|Yiisoft\Db\Query\QueryInterface|string|null

The array value which can be represented as

  • an array of values;
  • an instance of {@see \Traversable} or {@see \Yiisoft\Db\Schema\Data\LazyArrayInterface} that represents an array of values;
  • an instance of {@see \Yiisoft\Db\Query\QueryInterface} that represents an SQL sub-query;
  • a string retrieved value from the database that can be parsed into an array;
  • null.
$type Yiisoft\Db\Schema\Column\ColumnInterface|string|null

The array column type which can be represented as

  • a native database column type;
  • an {@see \Yiisoft\Db\Expression\Value\ColumnType abstract} type;
  • an instance of {@see \Yiisoft\Db\Schema\Column\ColumnInterface};
  • null if the type isn't explicitly specified.

String type will be converted into {@see \Yiisoft\Db\Schema\Column\ColumnInterface} using {@see \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 {@see \Yiisoft\Db\QueryBuilder\ColumnDefinitionBuilderInterface::buildType()} method will be invoked to convert {@see \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 {@see \Yiisoft\Db\Expression\Value\ColumnBuilder} to generate the column type as an instance of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}.

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