Propose a new function - list_is_empty
Peter Smith <smithpb2250@gmail.com>
From: Peter Smith <smithpb2250@gmail.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2022-08-16T01:19:47Z
Lists: pgsql-hackers
Attachments
- v1-0002-list_is_empty-use-the-new-function.patch (application/octet-stream) patch v1-0002
- v1-0001-list_is_empty-new-function.patch (application/octet-stream) patch v1-0001
During a recent code review I was going to suggest that some new code would be more readable if the following: if (list_length(alist) == 0) ... was replaced with: if (list_is_empty(alist)) ... but then I found that actually no such function exists. ~~~ Searching the PG source found many cases using all kinds of inconsistent ways to test for empty Lists: e.g.1 if (list_length(alist) > 0) e.g.2 if (list_length(alist) == 0) e.g.3 if (list_length(alist) != 0) e.g.4 if (list_length(alist) >= 1) e.g.5 if (list_length(alist) < 1) Of course, all of them work OK as-is, but by using list_is_empty all those can be made consistent and often also more readable as to the code intent. Patch 0001 adds a new function 'list_is_empty'. Patch 0002 makes use of it. Thoughts? ------ Kind Regards, Peter Smith. Fujitsu Australia
Commits
-
Avoid using list_length() to test for empty list.
- efd0c16becbf 16.0 landed