Available in versions: Dev (3.18)

This is experimental functionality, and as such subject to change. Use at your own risk!

This documentation is for the unreleased development version of jOOQ. Click on the above version links to get this documentation for a supported version of jOOQ.

COUNT(const)

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

The COUNT(expression) aggregate function counts the number of non-NULL expression evaluations in the group. If the expression is a constant, then there are only two options:

  • The constant is NULL, in case of which the COUNT(NULL) value is always 0 (but that's not an aggregate function, so we're currently not replacing it yet)
  • The constant is anything else, in case of which the COUNT(const) value is always COUNT(*)

For clarity reasons, and in some RDBMS also for (slight) performance reasons, COUNT(*) should be preferred.

Using Settings.transformPatternsCountConstant, the following transformations can be achieved:

-- With Settings.transformPatternsCountConstant active, this:
SELECT
  COUNT(NULL),
  COUNT(1);

-- ... is transformed into the equivalent expression:
SELECT
  COUNT(NULL), -- Might be replaced by 0 in the future, if other aggregates are present
  COUNT(*);

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo