Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Pgsql Doctrine Round Function

Pgsql Doctrine Round Function Laravel Package

kspitfire/pgsql-doctrine-round-function

Adds PostgreSQL ROUND() support to Doctrine ORM and DBAL. Register the custom DQL function to use ROUND in your queries with PostgreSQL, including numeric rounding with scale, without raw SQL. Lightweight and easy to configure in Symfony or plain Doctrine.

View on GitHub
Deep Wiki
Context7

ROUND() function implementation for Doctrine DQL

Frequently asked questions about Pgsql Doctrine Round Function
How do I install kspitfire/pgsql-doctrine-round-function?
Install it with Composer using composer require kspitfire/pgsql-doctrine-round-function. The package is a single Doctrine DQL function class with no service provider or Laravel auto-discovery, so there is nothing to publish or configure after installation. You still need to register the function with your Doctrine EntityManager before it can be used in DQL. Check the composer.json constraints first to confirm it matches your PHP and doctrine/orm versions.
Does kspitfire/pgsql-doctrine-round-function work with Laravel Eloquent?
No. This is a Doctrine ORM DQL custom function, not an Eloquent feature, so it only applies where Doctrine ORM is the persistence layer and PostgreSQL is the database. In a pure Eloquent application, use DB::raw('ROUND(col, 2)'), selectRaw, or a cast or accessor instead. It can still be useful in a Laravel app that uses Doctrine alongside Eloquent.
How do I register the ROUND DQL function in Laravel with Doctrine?
Register the function class with Doctrine's configuration using addCustomNumericFunction, mapping the DQL name round to the package class. In a Laravel Doctrine setup, that typically means adding it to the DQL functions section of your doctrine configuration. Registration is manual and applies per EntityManager or connection, so repeat it anywhere you build a separate EntityManager. After registering, run a DQL query and inspect the generated SQL to confirm it emits PostgreSQL round().
Which Laravel, PHP, and Doctrine ORM versions does the package support?
The package does not declare Laravel version support because it has no Laravel-specific code, and its compatibility is defined by its Composer constraints for PHP and doctrine/orm. The 1.3 release refreshed those constraints, so verify the actual composer.json rather than assuming the 2019 requirements still apply. Test that it installs cleanly on your target stack without --ignore-platform-reqs. The release notes do not state whether 1.3 targets Doctrine ORM 3.x or remains 2.x only.
How do I use ROUND with a precision or scale argument in DQL?
Once registered, write ROUND(value) or ROUND(value, 2) directly in your DQL and the function maps it to PostgreSQL's native round(). The optional second argument provides precision for numeric and decimal columns. Confirm that the package handles both arities in your Doctrine version, since the README excerpt does not document argument handling in detail. Check the generated SQL for numeric versus double precision columns to be sure the result type is what you expect.
Why does Doctrine's built-in ROUND fail on PostgreSQL numeric columns?
Doctrine's built-in numeric handling often falls short on PostgreSQL, particularly with numeric and decimal column types and the optional precision argument. Without a registered DQL function, ROUND in DQL either is not parsed or does not map cleanly to PostgreSQL's round() behavior. This package fills that gap by registering ROUND for PostgreSQL so queries behave predictably. Be aware of the round(numeric, int) versus round(double precision) distinction when checking results.
Is kspitfire/pgsql-doctrine-round-function still maintained and safe for production?
Treat it as resurrected rather than actively maintained. Version 1.3 arrived after roughly six years without a release, and its one-line note calling it the first stable and working version is a weak liveness signal, not a maintenance commitment. It has no dependents or issue history, so there is little battle-testing. Read the diff or changelog before pinning a constraint, and consider owning the roughly 40 to 80 lines yourself if long-term stability matters.
Can I use this package outside Laravel, for example in Symfony or plain Doctrine?
Yes. It is a plain Doctrine DQL function with no Laravel dependency, so it works in Symfony or any standalone Doctrine setup. Register it through addCustomNumericFunction in your Doctrine configuration for each EntityManager that needs it. The same manual registration rule applies everywhere, since the package ships no bundle, service provider, or auto-configuration.
Does the package include tests, and how should I test ROUND in my own app?
The release notes and excerpt do not describe a test suite, so do not assume one exists or that it runs against a real PostgreSQL instance. Write your own integration test that registers the function, runs a DQL query with and without a precision argument, and asserts both the generated SQL and the hydrated value. Include edge cases such as null input, negative scale, and numeric versus double precision columns. A real PostgreSQL connection is more trustworthy here than a mocked query walker.
What are the alternatives to this package for rounding in PostgreSQL?
For Eloquent, use DB::raw, selectRaw, or a cast and accessor rather than adding a DQL function. With Doctrine, you can write a small custom FunctionNode yourself in roughly 40 to 80 lines, which removes the dependency and the multi-year release gap risk. Native SQL queries or a database view are also options when the rounding is confined to reporting. Choosing the package mainly saves you that small amount of code at the cost of an extra lockfile entry and CVE scan scope.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
robertmarney/lara-hierarchial-collections
simonschaufi/rule-doc-generator
emissaoja/emissaoja
blackbricksoftware/gravityforms-civicrm-form-processor
al-rahabi/fancy-crud
jinas/dhivatar-component
mltstephane/laravel-quality
bernskiold/laravel-talentlms
bernskioldmedia/laravel-form-architect