int4->bool test coverage

Lists: pgsql-hackers
From: Christoph Berg <myon(at)debian(dot)org>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: int4->bool test coverage
Date: 2023-12-21 10:56:22
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

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

Attachment Content-Type Size
0001-Add-tests-for-int4_bool.patch text/x-diff 1.4 KB

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Christoph Berg <myon(at)debian(dot)org>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: int4->bool test coverage
Date: 2023-12-22 02:48:11
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Dec 21, 2023 at 11:56:22AM +0100, Christoph Berg wrote:
> The first cast is the int4_bool function, but it isn't covered by the
> regression tests at all. The attached patch adds tests.

I don't see why not.

Interesting that there are a few more of these in int.c, like int2up,
int4inc, int2smaller, int{2,4}shr, int{2,4}not, etc.
--
Michael


From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Christoph Berg <myon(at)debian(dot)org>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: int4->bool test coverage
Date: 2024-01-31 06:08:58
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Dec 22, 2023 at 11:48:11AM +0900, Michael Paquier wrote:
> On Thu, Dec 21, 2023 at 11:56:22AM +0100, Christoph Berg wrote:
>> The first cast is the int4_bool function, but it isn't covered by the
>> regression tests at all. The attached patch adds tests.
>
> I don't see why not.

And one month later, done.

> Interesting that there are a few more of these in int.c, like int2up,
> int4inc, int2smaller, int{2,4}shr, int{2,4}not, etc.

I've left these out for now.
--
Michael