int4->bool test coverage

Christoph Berg <myon@debian.org>

From: Christoph Berg <myon@debian.org>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2023-12-21T10:56:22Z
Lists: pgsql-hackers

Attachments

I was surprised to learn that 2 is a valid boolean (thanks Berge):

# select 2::boolean;
 bool
──────
 t

... while '2' is not:

# select '2'::boolean;
ERROR:  22P02: invalid input syntax for type boolean: "2"
LINE 1: select '2'::boolean;
               ^
LOCATION:  boolin, bool.c:151


The first cast is the int4_bool function, but it isn't covered by the
regression tests at all. The attached patch adds tests.

Christoph

Commits

  1. Add tests for int4_bool() in int.c