Re: int4 <-> bool casts - Mailing list pgsql-patches

From Tom Lane
Subject Re: int4 <-> bool casts
Date
Msg-id 24579.1109619439@sss.pgh.pa.us
Whole thread Raw
In response to Re: int4 <-> bool casts  (Peter Eisentraut <peter_e@gmx.net>)
List pgsql-patches
Peter Eisentraut <peter_e@gmx.net> writes:
> I believe I would have objected to an int/bool cast. I do so now
> anyway.

This was already discussed and agreed to.  Since it's an explicit-only
cast, I see no harm in it.  And it's certainly been requested often
enough.

> - Casting back and forth does not preserve information.  (This may be
> true for some other type pairs as well, but in this case it's true in
> almost every instance.)

On those grounds we should disallow most of the numeric-category casts.

> - It's an arbitary definition that is not obviously supported by
> mathematical or similar principles.

Nonetheless, the convention 0=false, 1=true is widely recognized.

> - It opens the door for other silly casts like empty string => false,
> non-empty string => true.

I haven't seen any requests for any such casts.  This cast is responding
to market demand, no more.

> - It's unnecessary because you can express the same thing using other
> expressions that clearly state what they do.

Basically what this is for is building in a feature that people
otherwise build for themselves.  On the grounds of "it's unnecessary"
we could throw away large chunks of Postgres :-)

            regards, tom lane

pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Patch for Array min() / max()
Next
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] snprintf causes regression tests to fail