# ColumnSchema

> Represents the metadata of a column in a PostgreSQL database table.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [db](/docs/api/yii/db/index.md) › [pgsql](/docs/api/yii/db/pgsql/index.md) › ColumnSchema

| class | `yii\db\pgsql\ColumnSchema` |
| --- | --- |
| Extends | [`yii\db\ColumnSchema`](/docs/api/yii/db/columnschema/index.md) » [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Since | 2.0 |
| Source | [`framework/db/pgsql/ColumnSchema.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/db/pgsql/ColumnSchema.php#L36) |

Represents the metadata of a column in a PostgreSQL database table.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-allowNull"></span>[`$allowNull`](/docs/api/yii/db/columnschema/index.md#property-allowNull) | `bool` | Whether this column can be null. Default: `false`. | [`yii\db\ColumnSchema`](/docs/api/yii/db/columnschema/index.md) |
| <span id="property-autoIncrement"></span>[`$autoIncrement`](/docs/api/yii/db/columnschema/index.md#property-autoIncrement) | `bool` | Whether this column is auto-incremental Default: `false`. | [`yii\db\ColumnSchema`](/docs/api/yii/db/columnschema/index.md) |
| <span id="property-comment"></span>[`$comment`](/docs/api/yii/db/columnschema/index.md#property-comment) | `string\|null` | Comment of this column. Default: `null`. | [`yii\db\ColumnSchema`](/docs/api/yii/db/columnschema/index.md) |
| <span id="property-dbType"></span>[`$dbType`](/docs/api/yii/db/columnschema/index.md#property-dbType) | `string` | The DB type of this column. Default: `''`. | [`yii\db\ColumnSchema`](/docs/api/yii/db/columnschema/index.md) |
| <span id="property-defaultValue"></span>[`$defaultValue`](/docs/api/yii/db/columnschema/index.md#property-defaultValue) | `mixed` | Default value of this column Default: `null`. | [`yii\db\ColumnSchema`](/docs/api/yii/db/columnschema/index.md) |
| [`$dimension`](#property-dimension) | `int` | The dimension of array. Default: `0`. | `ColumnSchema` |
| <span id="property-enumValues"></span>[`$enumValues`](/docs/api/yii/db/columnschema/index.md#property-enumValues) | `array\|null` | Enumerable values. Default: `null`. | [`yii\db\ColumnSchema`](/docs/api/yii/db/columnschema/index.md) |
| <span id="property-isPrimaryKey"></span>[`$isPrimaryKey`](/docs/api/yii/db/columnschema/index.md#property-isPrimaryKey) | `bool\|null` | Whether this column is a primary key Default: `null`. | [`yii\db\ColumnSchema`](/docs/api/yii/db/columnschema/index.md) |
| <span id="property-name"></span>[`$name`](/docs/api/yii/db/columnschema/index.md#property-name) | `string` | Name of this column (without quotes). Default: `''`. | [`yii\db\ColumnSchema`](/docs/api/yii/db/columnschema/index.md) |
| <span id="property-phpType"></span>[`$phpType`](/docs/api/yii/db/columnschema/index.md#property-phpType) | `string` | The PHP type of this column. Default: `''`. | [`yii\db\ColumnSchema`](/docs/api/yii/db/columnschema/index.md) |
| <span id="property-precision"></span>[`$precision`](/docs/api/yii/db/columnschema/index.md#property-precision) | `int\|null` | Precision of the column data, if it is numeric. Default: `null`. | [`yii\db\ColumnSchema`](/docs/api/yii/db/columnschema/index.md) |
| <span id="property-scale"></span>[`$scale`](/docs/api/yii/db/columnschema/index.md#property-scale) | `int\|null` | Scale of the column data, if it is numeric. Default: `null`. | [`yii\db\ColumnSchema`](/docs/api/yii/db/columnschema/index.md) |
| <span id="property-sequenceName"></span>`$sequenceName` | `string\|null` | Name of associated sequence if column is auto-incremental. `null` if no sequence. Default: `null`. Available since 2.0.29. | `ColumnSchema` |
| <span id="property-size"></span>[`$size`](/docs/api/yii/db/columnschema/index.md#property-size) | `int\|null` | Display size of the column. Default: `null`. | [`yii\db\ColumnSchema`](/docs/api/yii/db/columnschema/index.md) |
| <span id="property-type"></span>[`$type`](/docs/api/yii/db/columnschema/index.md#property-type) | `string` | Abstract type of this column. Default: `''`. | [`yii\db\ColumnSchema`](/docs/api/yii/db/columnschema/index.md) |
| <span id="property-unsigned"></span>[`$unsigned`](/docs/api/yii/db/columnschema/index.md#property-unsigned) | `bool` | Whether this column is unsigned. Default: `false`. | [`yii\db\ColumnSchema`](/docs/api/yii/db/columnschema/index.md) |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/baseobject/index.md#method-__construct) | Constructor. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/baseobject/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/baseobject/index.md#method-__get) | Returns the value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/baseobject/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/baseobject/index.md#method-__set) | Sets value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/baseobject/index.md#method-__unset) | Sets an object property to null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| [`dbTypecast()`](#method-dbTypecast) | Converts the input value according to [`$type`](/docs/api/yii/db/columnschema/index.md#property-type) and [`$dbType`](/docs/api/yii/db/columnschema/index.md#property-dbType) for use in a db query. | `ColumnSchema` |
| [`defaultPhpTypecast()`](#method-defaultPhpTypecast) | Converts a PostgreSQL column default value to its PHP representation. | `ColumnSchema` |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/baseobject/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/baseobject/index.md#method-hasProperty) | Returns a value indicating whether a property is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-init"></span>[`init()`](/docs/api/yii/base/baseobject/index.md#method-init) | Initializes the object. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-isType"></span>[`isType()`](/docs/api/yii/db/columnschema/index.md#method-isType) | Returns whether this column uses the given abstract type. | [`yii\db\ColumnSchema`](/docs/api/yii/db/columnschema/index.md) |
| [`phpTypecast()`](#method-phpTypecast) | Converts the input value according to [`$phpType`](/docs/api/yii/db/columnschema/index.md#property-phpType) after retrieval from the database. | `ColumnSchema` |
| [`getArrayParser()`](#method-getArrayParser) protected | Creates instance of ArrayParser | `ColumnSchema` |
| [`phpTypecastValue()`](#method-phpTypecastValue) protected | Casts $value after retrieving from the DBMS to PHP representation. | `ColumnSchema` |
| <span id="method-typecast"></span>[`typecast()`](/docs/api/yii/db/columnschema/index.md#method-typecast) protected | Converts the input value according to [`$phpType`](/docs/api/yii/db/columnschema/index.md#property-phpType) after retrieval from the database. | [`yii\db\ColumnSchema`](/docs/api/yii/db/columnschema/index.md) |

## Property details

### $dimension <span id="property-dimension"></span>

```php
public int $dimension = 0
```

The dimension of array.

Defaults to 0, means this column is not an array.

## Method details

### dbTypecast() <span id="method-dbTypecast"></span>

```php
public function dbTypecast(mixed $value): mixed
```

Converts the input value according to [`$type`](/docs/api/yii/db/columnschema/index.md#property-type) and [`$dbType`](/docs/api/yii/db/columnschema/index.md#property-dbType) for use in a db query.

If the value is null or an [`Expression`](/docs/api/yii/db/expression/index.md), it will not be converted.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | Input value |

**Returns**

`mixed`: Converted value. This may also be an array containing the value as the first element and the PDO type as the second element.

### defaultPhpTypecast() <span id="method-defaultPhpTypecast"></span>

```php
public function defaultPhpTypecast(mixed $value): mixed
```

Converts a PostgreSQL column default value to its PHP representation.

Recognizes the literal formats produced by `pg_get_expr()` and typecasts only those:
- `NULL` or `(NULL)`, optionally followed by a direct type cast, to `null`.
- Binary bit literals (`B'...'::`) to their integer value via `bindec()`; kept for backward compatibility,
  `pg_get_expr()` reports bit defaults in the quoted form.
- Quoted bit literals (`'...'::"bit"`) to their integer value via `bindec()`; `bit varying` defaults carry the
  same `"bit"` cast label.
- Quoted literals with a cast (`'value'::type`, including type modifiers such as `character varying(10)`) to
  the unquoted value with doubled quotes unescaped, delegated to [`phpTypecast()`](/docs/api/yii/db/pgsql/columnschema/index.md#method-phpTypecast).
- Numeric literals, optionally parenthesized and optionally cast (`42`, `1.5`, `(0)::numeric`), delegated to
  [`phpTypecast()`](/docs/api/yii/db/pgsql/columnschema/index.md#method-phpTypecast).
- Bare `true`/`false` to booleans.

Everything else — operator expressions, function calls, `nextval(...)`, `CURRENT_*` keywords — becomes an
executable [`Expression`](/docs/api/yii/db/expression/index.md). Branch order is significant: the bit branches must precede the generic
quoted-literal branch, or bit strings would be typecast as plain integers.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | Raw default value in PostgreSQL schema metadata format. |

**Returns**

`mixed`: Converted PHP value.

**Since**

22.0

### phpTypecast() <span id="method-phpTypecast"></span>

```php
public function phpTypecast(mixed $value): mixed
```

Converts the input value according to [`$phpType`](/docs/api/yii/db/columnschema/index.md#property-phpType) after retrieval from the database.

If the value is null or an [`Expression`](/docs/api/yii/db/expression/index.md), it will not be converted.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | Input value |

**Returns**

`mixed`: Converted value

### getArrayParser() <span id="method-getArrayParser"></span>

```php
protected function getArrayParser(): yii\db\pgsql\ArrayParser
```

Creates instance of ArrayParser

**Returns**

[`ArrayParser`](/docs/api/yii/db/pgsql/arrayparser/index.md)

### phpTypecastValue() <span id="method-phpTypecastValue"></span>

```php
protected function phpTypecastValue(string|null $value): bool|mixed|null
```

Casts $value after retrieving from the DBMS to PHP representation.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string\|null` |  |

**Returns**

`bool|mixed|null`