PHPackages                             tigrov/yii2-pgsql - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. tigrov/yii2-pgsql

ActiveYii2-extension[Database &amp; ORM](/categories/database)

tigrov/yii2-pgsql
=================

Improved PostgreSQL schemas for Yii2

1.4.4(4y ago)3467.0k↓26.5%6[2 issues](https://github.com/Tigrov/yii2-pgsql/issues)MITPHPCI failing

Since May 3Pushed 4y ago5 watchersCompare

[ Source](https://github.com/Tigrov/yii2-pgsql)[ Packagist](https://packagist.org/packages/tigrov/yii2-pgsql)[ RSS](/packages/tigrov-yii2-pgsql/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (24)Used By (0)

yii2-pgsql
==========

[](#yii2-pgsql)

Improved PostgreSQL schemas for Yii2.

Yii 2.0.14 and above supports `array` and `json` DB types.

Supports follow types for ActiveRecord models:

- `array`, Yii 2.0.14 and above supports `array` DB type
- `json`, Yii 2.0.14 and above supports `json` DB type
- [`composite`](docs/composite.md),
- `domain`,
- fixes type `bit`, issue [\#7682](https://github.com/yiisoft/yii2/issues/7682)
- converts Postgres types `timestamp`, `date` and `time` to PHP type `\DateTime` and vice versa.

[![Latest Stable Version](https://camo.githubusercontent.com/89239fad506e8d6e6378e5f4b816ab005a34c57bcda8e9fa0d83fa94f48e08f5/68747470733a2f2f706f7365722e707567782e6f72672f546967726f762f796969322d706773716c2f762f737461626c65)](https://packagist.org/packages/Tigrov/yii2-pgsql)[![Build Status](https://camo.githubusercontent.com/50532d7c7f4b3ce6abf1ba511bb6e57357333d33cae4818c5773fc5bfe31964e/68747470733a2f2f7472617669732d63692e6f72672f546967726f762f796969322d706773716c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Tigrov/yii2-pgsql)

Limitation
----------

[](#limitation)

Since version 1.2.0 requires Yii 2.0.14 and above.
You can use version 1.1.11 if you have Yii 2.0.13 and below.

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist tigrov/yii2-pgsql

```

or add

```
"tigrov/yii2-pgsql": "~1.0"

```

to the require section of your `composer.json` file.

Configuration
-------------

[](#configuration)

Once the extension is installed, add following code to your application configuration:

```
return [
    //...
    'components' => [
        'db' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'pgsql:host=localhost;dbname=',
            'username' => 'postgres',
            'password' => '',
            'schemaMap' => [
                'pgsql'=> 'tigrov\pgsql\Schema',
            ],
        ],
    ],
];
```

Specify the desired types for a table

```
CREATE TABLE public.model (
    id serial NOT NULL,
    attribute1 text[],
    attribute2 jsonb,
    attribute3 timestamp DEFAULT now(),
    CONSTRAINT model_pkey PRIMARY KEY (id)
);
```

Configure Model's rules

```
/**
 * @property string[] $attribute1 array of string
 * @property array $attribute2 associative array or just array
 * @property integer|string|\DateTime $attribute3 for more information about the type see \Yii::$app->formatter->asDatetime()
 */
class Model extends ActiveRecord
{
    //...
    public function rules()
    {
        return [
            [['attribute1'], 'each', 'rule' => ['string']],
            [['attribute2', 'attribute3'], 'safe'],
        ];
    }
}
```

Usage
-----

[](#usage)

You can then save array, json and timestamp types in database as follows:

```
/**
 * @var ActiveRecord $model
 */
$model->attribute1 = ['some', 'values', 'of', 'array'];
$model->attribute2 = ['some' => 'values', 'of' => 'array'];
$model->attribute3 = new \DateTime('now');
$model->save();
```

and then use them in your code

```
/**
 * @var ActiveRecord $model
 */
$model = Model::findOne($pk);
$model->attribute1; // is array
$model->attribute2; // is associative array (decoded json)
$model->attribute3; // is \DateTime
```

[Composite types](docs/composite.md)

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community12

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~73 days

Recently: every ~189 days

Total

23

Last Release

1682d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/77d285672dec831b7ce5746ab8bb1dd20fffe81fb9d11c232534686706de9697?d=identicon)[Tigros](/maintainers/Tigros)

---

Top Contributors

[![Tigrov](https://avatars.githubusercontent.com/u/8563175?v=4)](https://github.com/Tigrov "Tigrov (51 commits)")

---

Tags

pgsqlpostgrespostgresqlyii2yii2-extensionjsonarraypostgresqlpostgrespgsqldatetimecompositeyii2extensiondomaintimestampbit

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tigrov-yii2-pgsql/health.svg)

```
[![Health](https://phpackages.com/badges/tigrov-yii2-pgsql/health.svg)](https://phpackages.com/packages/tigrov-yii2-pgsql)
```

###  Alternatives

[martin-georgiev/postgresql-for-doctrine

Extends Doctrine with native PostgreSQL support for arrays, JSONB, ranges, PostGIS geometries, text search, ltree, uuid, and 100+ PostgreSQL-specific functions.

4485.3M4](/packages/martin-georgiev-postgresql-for-doctrine)[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58723.9M36](/packages/scienta-doctrine-json-functions)[aura/sql

A PDO extension that provides lazy connections, array quoting, query profiling, value binding, and convenience methods for common fetch styles. Because it extends PDO, existing code that uses PDO can use this without any changes to the existing code.

5632.5M43](/packages/aura-sql)[aura/sqlquery

Object-oriented query builders for MySQL, Postgres, SQLite, and SQLServer; can be used with any database connection library.

4572.9M34](/packages/aura-sqlquery)[sad_spirit/pg_wrapper

Converter of complex PostgreSQL types and an OO wrapper for PHP's pgsql extension

2211.2k2](/packages/sad-spirit-pg-wrapper)[nanson/yii2-postgis

Yii2-extension to work with postgis data

1851.6k](/packages/nanson-yii2-postgis)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
