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.
Package info
github.com/martin-georgiev/postgresql-for-doctrine
pkg:composer/martin-georgiev/postgresql-for-doctrine
Requires
- php: ^8.2 <8.6
- ext-ctype: *
- ext-json: *
- ext-mbstring: *
- doctrine/dbal: ~2.10||~3.0||~4.0
Requires (Dev)
- brianium/paratest: ^7.0
- deptrac/deptrac: ^4.0
- doctrine/orm: ~2.14||~3.0
- ekino/phpstan-banned-code: ^3.2.0
- friendsofphp/php-cs-fixer: ^3.95.2
- phpstan/phpstan: ^2.1.55
- phpstan/phpstan-deprecation-rules: ^2.0.4
- phpstan/phpstan-doctrine: ^2.0.22
- phpstan/phpstan-phpunit: ^2.0.16
- phpunit/phpunit: ^10.5.63||^11.5
- rector/rector: ^2.4.4
- symfony/cache: ^6.4||^7.0
- symfony/var-exporter: ^6.4||^7.0
Suggests
- php: ^8.4
- doctrine/orm: ~2.14||~3.0
- dev-main
- v4.6.0
- v4.5.1
- v4.5.0
- v4.4.0
- v4.3.0
- v4.2.0
- v4.1.0
- v4.0.0
- v3.7.0
- v3.6.2
- v3.6.1
- v3.6.0
- v3.5.1
- v3.5.0
- v3.4.1
- v3.4.0
- v3.3.0
- v3.2.2
- v3.2.1
- v3.2.0
- v3.1.0
- v3.0.2
- v3.0.1
- v3.0.0
- v2.10.3
- v2.10.2
- v2.10.1
- v2.10.0
- v2.9.0
- v2.8.0
- v2.7.0
- v2.6.0
- v2.5.0
- v2.4.1
- v2.4.0
- v2.3.2
- v2.3.1
- v2.3.0
- v2.2.0
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.1
- v2.0.0
- v1.8.0
- v1.7.0
- v1.6.0
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.1
- v1.4.0
- v1.3.0
- v1.2.2
- v1.2.1
- v1.2
- v1.1
- v1.0.1
- v1.0
- v0.12
- v0.11
- 0.10
- 0.9
- 0.8.1
- 0.8
- 0.7
- 0.6.2
- 0.6.1
- 0.6
- 0.5
- 0.4
- 0.3
- 0.2
- 0.1.1
- 0.1
- dev-release-please--branches--main
- dev-renovate/major-composer-dev
- dev-statistical-aggregate-dqls
- dev-feat/string-dql-functions
- dev-datetime-dqls
- dev-feat/hstore-dql-functions
- dev-feat/xml-dql-functions
- dev-docs
- dev-clean-up-docs-from-noise
- dev-tests-method-renaming-and-standardization
- dev-catch-up-on-ai-tools-instructions
- dev-feat/citext-dbal-type
- dev-feat/range-array-dbal-types
- dev-composer-abandoned
- dev-renovate/composer-qa-tooling
- dev-feat/timetz-dbal-type
- dev-feat/multirange-array-dbal-types
- dev-enum
- dev-hstore
- dev-bytea
- dev-feature/abstract-enum-type
- dev-feature/hstore-type
- dev-feature/bytea-type
- dev-tests-coverage
- dev-issue-616
This package is auto-updated.
Last update: 2026-05-29 19:11:41 UTC
README
PostgreSQL for Doctrine
Enhances Doctrine with PostgreSQL-specific features and functions. Supports PostgreSQL 9.4+ and PHP 8.2+.
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
Data Types
- Array Types
- Integer arrays (
int[],smallint[],bigint[]) - Float arrays (
real[],double precision[]) - Text arrays (
text[]) - Boolean arrays (
bool[]) - JSONB arrays (
jsonb[])
- Integer arrays (
- Binary Types
- Raw binary data (
bytea,bytea[])
- Raw binary data (
- Bit String Types
- Fixed-length bit strings (
bit,bit[]) - Variable-length bit strings (
bit varying,bit varying[])
- Fixed-length bit strings (
- 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[])
- IP addresses (
- 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[])
- Box (
- 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 ranges (
- Date and Time Types
- Arrays (
date[],timestamp[],timestamptz[]) - Time durations with
DateIntervalsupport (interval,interval[]) - String-represented time with timezone (
timetz,timetz[])
- Arrays (
- Text Search Types
- Full-text search document (
tsvector,tsvector[]) - Full-text search query (
tsquery,tsquery[])
- Full-text search document (
- Case-Insensitive Text Types (requires citext extension)
- Case-insensitive text (
citext,citext[])
- Case-insensitive text (
- Key-Value Types (requires hstore extension)
- Key-value store (
hstore,hstore[])
- Key-value store (
- Monetary Types
- Currency amounts (
money,money[])
- Currency amounts (
- XML Types
- Native XML document storage (
xml,xml[])
- Native XML document storage (
- Hierarchical Types
- Label-tree data (
ltree,ltree[])
- Label-tree data (
- Vector Types (requires pgvector extension)
- Fixed-dimension float vector (
vector) - Half-precision float vector (
halfvec) - Sparse vector (
sparsevec)
- Fixed-dimension float vector (
- Enum Types
- User-defined PostgreSQL enum types via
Enumbase class
- User-defined PostgreSQL enum types via
- Composite Types
- Access fields from user-defined composite types via
COMPOSITE_FIELD()function
- Access fields from user-defined composite types via
PostgreSQL Operators
- Array Operations
- Contains (
@>) - Is contained by (
<@) - Overlaps (
&&) - Array aggregation with ordering
- Contains (
- JSON Operations
- Field access (
->,->>) - Path operations (
#>,#>>) - JSON containment and existence operators
- Field access (
- Range Operations
- Containment checks (in PHP value objects and for DQL queries with
@>and<@) - Overlaps (
&&)
- Containment checks (in PHP value objects and for DQL queries with
- PostGIS Spatial Operations
- Bounding box relationships (
<<,>>,&<,&>,|&>,&<|,<<|,|>>) - Spatial containment (
@,~) - Distance calculations (
<->,<#>,<<->>,<<#>>,|=|) - N-dimensional operations (
&&&)
- Bounding box relationships (
Functions
- Text Search
- Full text search (
to_tsvector,to_tsquery) - Pattern matching (
ilike,similar to) - Regular expressions
- String manipulation (
ascii,btrim,char_length,chr,decode,encode,initcap,lpad,ltrim,octet_length,quote_ident,quote_literal,quote_nullable,rpad,rtrim,strpos,translate) - Trigram similarity (
similarity,word_similarity,strict_word_similarity) (requires pg_trgm extension) - Hashing & Checksum (
md5,sha224,sha256,sha384,sha512,crc32,crc32c,reversefor bytea)
- Full text search (
- Array Functions
- Generic array aggregation and manipulation (
array_agg,array_append,array_prepend,array_remove,array_replace,array_shuffle) - Array dimensions and length
- Special aggregates (
any_value)
- Generic array aggregation and manipulation (
- JSON Functions
- JSON construction (
json_build_object,jsonb_build_object) - JSON manipulation and transformation
- Row to JSON (
row_to_json,row)
- JSON construction (
- Date Functions
- Current timestamp functions (
clock_timestamp,statement_timestamp,transaction_timestamp) - Interval adjustment (
justify_days,justify_hours,justify_interval)
- Current timestamp functions (
- Aggregate Functions
- Aggregation with ordering and distinct (
array_agg,json_agg,jsonb_agg) - Statistical aggregates (
bool_and,bool_or,every,bit_and,bit_or,bit_xor,stddev,stddev_pop,var_pop,variance,corr,covar_pop,covar_samp) - Special aggregates (
any_value,xmlagg)
- Aggregation with ordering and distinct (
- Hstore Functions (requires hstore extension)
- Key and value extraction (
akeys,avals,skeys,svals) - Key inspection (
defined) - Key deletion (
delete) - JSON conversion (
hstore_to_json,hstore_to_json_loose)
- Key and value extraction (
- XML Functions
- XML aggregation, construction, manipulation, validation (
xmlagg,xmlcomment,xmlconcat,xml_is_well_formed) - XPath querying (
xpath,xpath_exists)
- XML aggregation, construction, manipulation, validation (
- Mathematical/Arithmetic Functions
- Trigonometric functions (
sin,cos,tan,asin,acos,atan, degree variants) - Hyperbolic functions (
sinh,cosh,tanh,asinh,acosh,atanh) - Number theory functions (
gcd,lcm,factorial,div) - Statistical functions (
erf,erfc,random_normal)
- Trigonometric functions (
- Range Functions
- Utility Functions
- Type casting (
cast) - Data formatting (
to_char,to_number) - UUID generation and inspection (
uuidv4,uuidv7,uuid_extract_timestamp,uuid_extract_version)
- Type casting (
- Vector Distance Functions
Full documentation:
- Available Types
- Value Objects for Range Types
- PostgreSQL ltree Types
- Available Functions and Operators - Overview and cross-references
- Common Use Cases and Examples
- Spatial Types
- Geometry Arrays
๐ฆ Installation
composer require martin-georgiev/postgresql-for-doctrine
๐ง Integration Guides
๐ก Usage Examples
See our Common Use Cases and Examples for detailed code samples.
๐งช Testing
Unit Tests
composer run-unit-tests
PostgreSQL Integration Tests
We also provide integration tests that run against a real PostgreSQL database with PostGIS:
# Start PostgreSQL with PostGIS using Docker Compose docker compose up -d # Run integration tests composer run-integration-tests # Stop PostgreSQL docker compose down -v
See tests/Integration/README.md for more details.
โญ Support the Project
๐ GitHub Sponsors
If you find this package useful for your projects, please consider sponsoring the development via GitHub Sponsors. Your support helps maintain this package, create new features, and improve documentation.
Benefits of sponsoring:
- Priority support for issues and feature requests
- Direct access to the maintainer
- Help sustain open-source development
Other Ways to Help
- Star the repository
- Report issues
- Contribute with code or documentation
- Share the project with others
๐ License
This package is licensed under the MIT License. See the LICENSE file for details.