PHPackages                             martin-georgiev/postgresql-for-doctrine - 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. martin-georgiev/postgresql-for-doctrine

ActiveLibrary[Database &amp; ORM](/categories/database)

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.

v4.6.0(1mo ago)4585.8M↓37.1%58[9 issues](https://github.com/martin-georgiev/postgresql-for-doctrine/issues)[1 PRs](https://github.com/martin-georgiev/postgresql-for-doctrine/pulls)4MITPHPPHP ^8.2 &lt;8.6CI passing

Since Jul 12Pushed 2w ago9 watchersCompare

[ Source](https://github.com/martin-georgiev/postgresql-for-doctrine)[ Packagist](https://packagist.org/packages/martin-georgiev/postgresql-for-doctrine)[ Fund](https://github.com/sponsors/martin-georgiev)[ GitHub Sponsors](https://github.com/martin-georgiev)[ RSS](/packages/martin-georgiev-postgresql-for-doctrine/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (10)Dependencies (55)Versions (113)Used By (4)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/696c2a74239c0d5ecd3c8af37148bea7532c4a2cfd3d8a0bd4a71977089f760a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d617274696e2d67656f72676965762f706f737467726573716c2d666f722d646f637472696e652f6261646765732f7175616c6974792d73636f72652e706e67)](https://scrutinizer-ci.com/g/martin-georgiev/postgresql-for-doctrine/?branch=main)[![Coverage Status](https://camo.githubusercontent.com/92f32bdaad3ee965e81074a4968317c2b381b93b7912a5b93105b5ec33f1c48c/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d617274696e2d67656f72676965762f706f737467726573716c2d666f722d646f637472696e652f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/martin-georgiev/postgresql-for-doctrine?branch=main)[![Latest Stable Version](https://camo.githubusercontent.com/07661b0c87290704aa6bd0b72ff5fd61fcf8b26d9e6af0eddfb8774153b69746/68747470733a2f2f706f7365722e707567782e6f72672f6d617274696e2d67656f72676965762f706f737467726573716c2d666f722d646f637472696e652f76657273696f6e)](https://packagist.org/packages/martin-georgiev/postgresql-for-doctrine)[![Total Downloads](https://camo.githubusercontent.com/72a5e75d6c39ea83ccc25c45972d801493564dc7fc2461816d42dd1df7e4ca0f/68747470733a2f2f706f7365722e707567782e6f72672f6d617274696e2d67656f72676965762f706f737467726573716c2d666f722d646f637472696e652f646f776e6c6f616473)](https://packagist.org/packages/martin-georgiev/postgresql-for-doctrine)

PostgreSQL for Doctrine
=======================

[](#postgresql-for-doctrine)

Enhances Doctrine with PostgreSQL-specific features and functions. Supports PostgreSQL 9.4+ and PHP 8.2+.

Quick Start
-----------

[](#quick-start)

```
use Doctrine\DBAL\Types\Type;
use MartinGeorgiev\Doctrine\DBAL\Type as PostgresType;

// Register types with Doctrine
Type::addType('jsonb', "MartinGeorgiev\\Doctrine\\DBAL\\Types\\Jsonb");
Type::addType('text[]', "MartinGeorgiev\\Doctrine\\DBAL\\Types\\TextArray");
Type::addType('numrange', "MartinGeorgiev\\Doctrine\\DBAL\\Types\\NumRange");

// Use in your Doctrine entities
#[ORM\Column(type: PostgresType::JSONB)]
private array $data;

#[ORM\Column(type: PostgresType::TEXT_ARRAY)]
private array $tags;

#[ORM\Column(type: PostgresType::NUMRANGE)]
private NumericRange $priceRange;

// Use in DQL
$query = $em->createQuery('
    SELECT e
    FROM App\Entity\Post e
    WHERE CONTAINS(e.tags, ARRAY(:tags)) = TRUE
    AND JSON_GET_FIELD(e.data, :field) = :value
');
```

🚀 Features Highlight
--------------------

[](#-features-highlight)

### Data Types

[](#data-types)

- **Array Types**
    - Integer arrays (`int[]`, `smallint[]`, `bigint[]`)
    - Float arrays (`real[]`, `double precision[]`)
    - Text arrays (`text[]`)
    - Boolean arrays (`bool[]`)
    - JSONB arrays (`jsonb[]`)
- **Binary Types**
    - Raw binary data (`bytea`, `bytea[]`)
- **Bit String Types**
    - Fixed-length bit strings (`bit`, `bit[]`)
    - Variable-length bit strings (`bit varying`, `bit varying[]`)
- **JSON Types**
    - Native JSONB support
    - JSON field operations
    - JSON construction and manipulation
- **Network Types**
    - IP addresses (`inet`, `inet[]`)
    - Network CIDR notation (`cidr`, `cidr[]`)
    - MAC addresses (`macaddr`, `macaddr[]`, `macaddr8`, `macaddr8[]`)
- **Geometric Types**
    - Box (`box`, `box[]`)
    - Circle (`circle`, `circle[]`)
    - Line (`line`, `line[]`)
    - Line segment (`lseg`, `lseg[]`)
    - Path (`path`, `path[]`)
    - Point (`point`, `point[]`)
    - Polygon (`polygon`, `polygon[]`)
    - PostGIS Geometry (`geometry`, `geometry[]`)
    - PostGIS Geography (`geography`, `geography[]`)
- **Range Types**
    - Date and time ranges (`daterange`, `daterange[]`, `tsrange`, `tsrange[]`, `tstzrange`, `tstzrange[]`)
    - Numeric ranges (`numrange`, `numrange[]`, `int4range`, `int4range[]`, `int8range`, `int8range[]`)
    - Multiranges (`datemultirange`, `datemultirange[]`, `int4multirange`, `int4multirange[]`, `int8multirange`, `int8multirange[]`, `nummultirange`, `nummultirange[]`, `tsmultirange`, `tsmultirange[]`, `tstzmultirange`, `tstzmultirange[]`)
- **Date and Time Types**
    - Arrays (`date[]`, `timestamp[]`, `timestamptz[]`)
    - Time durations with `DateInterval` support (`interval`, `interval[]`)
    - String-represented time with timezone (`timetz`, `timetz[]`)
- **Text Search Types**
    - Full-text search document (`tsvector`, `tsvector[]`)
    - Full-text search query (`tsquery`, `tsquery[]`)
- **Case-Insensitive Text Types** (requires [citext](https://www.postgresql.org/docs/18/citext.html) extension)
    - Case-insensitive text (`citext`, `citext[]`)
- **Key-Value Types** (requires [hstore](https://www.postgresql.org/docs/18/hstore.html) extension)
    - Key-value store (`hstore`, `hstore[]`)
- **Monetary Types**
    - Currency amounts (`money`, `money[]`)
- **XML Types**
    - Native XML document storage (`xml`, `xml[]`)
- **Hierarchical Types**
    - Label-tree data (`ltree`, `ltree[]`)
- **Vector Types** (requires [pgvector](https://github.com/pgvector/pgvector) extension)
    - Fixed-dimension float vector (`vector`)
    - Half-precision float vector (`halfvec`)
    - Sparse vector (`sparsevec`)
- **Enum Types**
    - User-defined PostgreSQL enum types [via `Enum` base class](docs/ENUM-TYPE.md)
- **Composite Types**
    - Access fields from [user-defined composite types](https://www.postgresql.org/docs/17/rowtypes.html) via `COMPOSITE_FIELD()` function

### PostgreSQL Operators

[](#postgresql-operators)

- **Array Operations**
    - Contains (`@>`)
    - Is contained by (``, `->>`)
    - Path operations (`#>`, `#>>`)
    - JSON containment and existence operators
- **Range Operations**
    - Containment checks (in PHP value objects and for DQL queries with `@>` and ``, `&
