qbbr/pgsql-doctrine-random-function
Adds PostgreSQL's RANDOM() function to Doctrine DBAL/ORM so you can select random rows in DQL queries. Registers the function with the PostgreSQL platform, letting you write ORDER BY RANDOM() without dropping to raw SQL.
ORDER BY RANDOM() — "random item of the day," shuffled quiz questions, random promo/coupon assignment, randomized onboarding samples, lottery/giveaway draws, A/B bucketing at the query layer, and "discover" or "surprise me" surfaces.App\Doctrine\Functions namespace. For most teams, the correct PM call is "reimplement in-house, use the package as reference."ORDER BY RANDOM() forces a full table scan and sort; on any large table this is a performance decision, not a library decision.Consider it when:
laravel-doctrine/orm or a Symfony/standalone Doctrine app).RANDOM() available inside DQL, so repositories avoid raw SQL and stay testable/composable.WHERE filters.Look elsewhere (or don't adopt) when:
inRandomOrder() already does this; the package is irrelevant.RANDOM() does not provide.TABLESAMPLE SYSTEM, random-offset pagination, or precomputed random columns), not a DQL function.To executives: This is a small, free (MIT) utility that unblocks a specific class of "randomized" product features — random picks, shuffles, and draws — for teams running PostgreSQL with Doctrine. It carries no license cost and no data/security exposure beyond reading your own database. The real risk is bus factor: three GitHub stars and zero downstream dependents mean nobody is watching it. Recommendation is to use it as a pattern to copy, not a dependency to install, which gives us the capability with no supply-chain exposure and no upgrade treadmill.
To engineering: One DQL function registration that teaches Doctrine about Postgres RANDOM(), letting you write ORDER BY RANDOM() in DQL instead of dropping to native SQL in repositories. It's roughly a single class — vendoring it into our own Doctrine\Functions namespace costs an afternoon and removes an unmaintained third-party from composer.json. Flag: the underlying SQL is ORDER BY RANDOM(), which is a full scan and sort; fine for filtered or small sets, a trap on large tables. If the feature is "random selection over the whole catalog," we should discuss TABLESAMPLE or a precomputed random-key column instead. Also worth an explicit decision: this only makes sense if we've committed to Doctrine + PostgreSQL, since Eloquent users already have inRandomOrder().
How can I help you explore Laravel packages today?