martin-georgiev/postgresql-for-doctrine
Adds PostgreSQL-specific power to Doctrine DBAL/ORM: rich native types (jsonb, arrays, ranges, network, geometric, etc.) plus DQL functions/operators for JSON and array querying. Supports PostgreSQL 9.4+ and PHP 8.2+.
This document provides an overview of PostgreSQL functions and operators available in this library. For detailed documentation of specific function categories, see the specialized documentation files linked below.
⚠️ Important: Some PostgreSQL operators have multiple meanings depending on the data types involved. This library provides specific DQL function names to avoid conflicts:
| Operator | Array/JSON Usage | Spatial Usage | Text/Pattern Usage |
|---|---|---|---|
@> |
CONTAINS (arrays contain elements) |
Works automatically with geometry/geography | N/A |
<@ |
IS_CONTAINED_BY (element in array) |
Works automatically with geometry/geography | N/A |
@ |
N/A | SPATIAL_CONTAINED_BY (bounding box contained) |
N/A |
~ |
N/A | SPATIAL_CONTAINS (bounding box contains) |
REGEXP (text pattern matching) |
&& |
OVERLAPS (arrays/ranges overlap) |
Works automatically with geometry/geography | N/A |
Usage Guidelines:
CONTAINS, IS_CONTAINED_BY, OVERLAPS for array and JSON operations → Array and JSON FunctionsSPATIAL_CONTAINS, SPATIAL_CONTAINED_BY for explicit spatial bounding box operations → PostGIS Spatial FunctionsREGEXP, IREGEXP for pattern matching → Text and Pattern Functions= TRUE or = FALSE in DQLThis library provides comprehensive PostgreSQL function and operator support organized into the following categories:
Complete documentation for array manipulation and JSON/JSONB operations.
@>, <@, &&), JSON operators (->, ->>, #>, #>>), array functions, JSON functions, JSONB functionsComplete documentation for PostGIS spatial operations and geometry processing.
Complete documentation for text processing, pattern matching, regular expressions, and hashing.
~, ilike, @@), regular expression functions, text processing functions, full-text search functions, fuzzy string matching functions, hashing and checksum functionsComplete documentation for date/time operations and range type functions.
Complete documentation for mathematical operations.
Complete documentation for type conversion, formatting, and UUID functions.
cast), data formatting (to_char, to_number), UUID generation and inspection (uuidv4, uuidv7, uuid_extract_timestamp, uuid_extract_version)Complete documentation for PostgreSQL XML processing, validation, and XPath querying.
xmlagg), XML validation (xml_is_well_formed, xml_is_well_formed_document, xml_is_well_formed_content), XML construction (xmltext, xmlcomment, xmlconcat), XPath querying (xpath, xpath_exists)Complete documentation for PostgreSQL network address operations on inet and cidr types.
HOST, BROADCAST, NETWORK, NETMASK, HOSTMASK, FAMILY, MASKLEN, ABBREV, INET_MERGE, INET_SAME_FAMILY, SET_MASKLENKey-value store operations using the PostgreSQL hstore type.
HSTORE_AKEYS, HSTORE_AVALS, HSTORE_SKEYS, HSTORE_SVALS, HSTORE_TO_JSON, HSTORE_TO_JSON_LOOSE, HSTORE_DEFINED, HSTORE_DELETEComplete documentation for PostgreSQL ltree (label tree) operations and hierarchical data processing.
Distance functions for fixed-dimension float vectors stored with the vector type.
L2_DISTANCE — Euclidean (L2) distance between two vectorsCOSINE_DISTANCE — Cosine distance between two vectorsINNER_PRODUCT — Inner (dot) product of two vectorsArray Operations: (Complete documentation)
CONTAINS (@>) - Test if array/range contains elementsOVERLAPS (&&) - Test if arrays/ranges overlapARRAY_AGG - Aggregate values into arraysJSON Operations: (Complete documentation)
JSON_GET_FIELD_AS_TEXT (->>) - Extract JSON field as textJSON_BUILD_OBJECT - Build JSON objectsJSONB_PATH_EXISTS - Test JSON path existenceSpatial Operations: (Complete documentation)
ST_INTERSECTS - Test if geometries intersectST_DISTANCE - Calculate distance between geometriesST_CONTAINS - Test spatial containmentText Operations: (Complete documentation)
ASCII - Get numeric code of first characterBTRIM/LTRIM/RTRIM - Trim characters from string endsCASEFOLD - Advanced case-insensitive text comparison with Unicode supportCHR - Get character from code pointILIKE - Case-insensitive pattern matchingINITCAP - Capitalize first letter of each wordLPAD/RPAD - Left/right pad a string to a given lengthQUOTE_IDENT/QUOTE_LITERAL/QUOTE_NULLABLE - Quote SQL identifiers and literalsREGEXP (~) - Regular expression matchingSTARTS_WITH - Test if text starts with a substringSTRPOS - Find position of substringTRANSLATE - Replace characters in a stringLEVENSHTEIN - Calculate edit distance between strings (fuzzy matching)SOUNDEX - Phonetic encoding for similarity matchingMD5/SHA256/SHA512 (and other SHA variants) - Cryptographic hashingCRC32/CRC32C - CRC checksum computationREVERSE_BYTES - Reverse byte order for bytea valuesDate/Range Operations: (Complete documentation)
CLOCK_TIMESTAMP - Current timestamp at call timeDATE_ADD - Add interval to dateDATE_EXTRACT - Extract date componentsDATERANGE - Create date rangesISFINITE - Test if date/timestamp/interval is finiteJUSTIFY_DAYS/JUSTIFY_HOURS/JUSTIFY_INTERVAL - Adjust interval representationsSTATEMENT_TIMESTAMP - Timestamp of current SQL statementTRANSACTION_TIMESTAMP - Timestamp of current transactionMathematical Operations: (Complete documentation)
DIV/GCD/LCM/FACTORIAL - Integer arithmetic functionsERF/ERFC - Error and complementary error functionsGAMMA/LGAMMA - Gamma function for statistical calculationsGREATEST/LEAST - Find maximum/minimum valuesROUND/SCALE/MIN_SCALE/TRIM_SCALE - Numeric precision functionsRANDOM/RANDOM_NORMAL - Generate random numbersBIT_AND, BIT_OR, BIT_XOR, BOOL_AND, BOOL_OR, EVERYCORR, COVAR_POP, COVAR_SAMP, STDDEV, STDDEV_POP, VAR_POP, VARIANCEUtility Functions: (Complete documentation)
CAST - General type conversionTO_CHAR - Convert numbers and dates to formatted stringsTO_NUMBER - Parse formatted text as numbersUUIDV4 - Explicit UUID version 4 generationUUIDV7 - Generate timestamp-ordered UUIDs (version 7) for better database performanceUUID_EXTRACT_TIMESTAMP - Extract timestamp from UUID v1 or v7UUID_EXTRACT_VERSION - Extract version number from UUIDNetwork Address Operations: (Complete documentation)
HOST/NETWORK/BROADCAST - Extract address partsMASKLEN/NETMASK/HOSTMASK - Mask informationINET_MERGE - Smallest network containing two addressesHstore Operations: (Complete documentation)
HSTORE_AKEYS - Return hstore keys as an arrayHSTORE_AVALS - Return hstore values as an arrayHSTORE_DEFINED - Check if key exists and is not NULLHSTORE_DELETE - Delete key from hstoreLtree Operations: (Complete documentation)
SUBLTREE - Extract subpath from ltreeSUBPATH - Extract subpath with offset and lengthNLEVEL - Get number of labels in pathINDEX - Find position of ltree in another ltreeLCA - Find longest common ancestorVector Distance Operations:
L2_DISTANCE - Euclidean distance between vectorsCOSINE_DISTANCE - Cosine distance between vectorsINNER_PRODUCT - Inner product of two vectorsComposite Types:
COMPOSITE_FIELD - Access a field from a PostgreSQL composite type column → Use Cases and ExamplesXML Functions: (Complete documentation)
XML_IS_WELL_FORMED - Check whether a text string is well-formed XMLXML_IS_WELL_FORMED_CONTENT - Check whether a text string is well-formed XML contentXML_IS_WELL_FORMED_DOCUMENT - Check whether a text string is a well-formed XML documentXMLAGG - Aggregate XML values (supports ORDER BY)XMLCOMMENT - Create an XML commentXMLCONCAT - Concatenate multiple XML values into a single XML valueXMLEXISTS - Test if an XPath expression matches any nodes in an XML valueXMLPI - Create an XML processing instructionXMLTEXT - Create an XML text node (with entity escaping)XPATH - Evaluate an XPath expression against an XML value, returning matched nodesXPATH_EXISTS - Test if an XPath expression matches any node in an XML valueascii, btrim, chr, initcap, lpad, ltrim, octet_length, quote_ident, quote_literal, quote_nullable, rpad, rtrim, strpos, translate, and more)akeys, skeys)avals, svals)defined)delete)hstore_to_json, hstore_to_json_loose)ltree and text typesCAST for general type conversionTO_CHAR for numbers and dates, TO_NUMBER for parsingUUIDV4, UUIDV7) and inspection (UUID_EXTRACT_TIMESTAMP, UUID_EXTRACT_VERSION)XMLAGG — aggregate XML values with optional orderingXML_IS_WELL_FORMED, XML_IS_WELL_FORMED_DOCUMENT, XML_IS_WELL_FORMED_CONTENT — check XML well-formednessXMLTEXT, XMLCOMMENT, XMLCONCAT, XMLPI — create and combine XML valuesXPATH, XPATH_EXISTS, XMLEXISTS — extract nodes and test existenceHOST, BROADCAST, NETWORK, NETMASK, HOSTMASK — decompose inet/cidr typesFAMILY, MASKLEN, ABBREV — address metadataINET_MERGE, INET_SAME_FAMILY — compare or combine addressesSET_MASKLEN — adjust subnet mask length💡 Tips for Usage:
= TRUE or = FALSE in DQL → Common Use Cases and Examples📖 For More Information:
How can I help you explore Laravel packages today?