Allow Casting from Boolean to other types, specifically to integer in pg-mem
Description:
This pull request addresses the limitation in pg-mem where casting from boolean to integer is not allowed. This feature is important for providing complete emulation of PostgreSQL, which supports such casting.
Changes:
Updated the BoolType class in datatypes.ts.
Modified the doCanCast() method to include DataType.integer as allowable casting targets for booleans.
Modified the doCast() method to correctly cast boolean values to integers (1 for true, 0 for false).
Why is this change necessary?
This change is necessary to ensure that pg-mem can emulate PostgreSQL as accurately as possible. The absence of this feature could lead to discrepancies between the behavior of pg-mem and PostgreSQL, especially when testing applications that depend on this particular casting behavior.
How does it solve the problem?
The modifications to the doCanCast() and doCast() methods in the BoolType class now allow for seamless casting from boolean to integer, emulating the same behavior in PostgreSQL.
Title:
Allow Casting from Boolean to other types, specifically to
integer
inpg-mem
Description:
This pull request addresses the limitation in
pg-mem
where casting from boolean to integer is not allowed. This feature is important for providing complete emulation of PostgreSQL, which supports such casting.Changes:
BoolType
class indatatypes.ts
.doCanCast()
method to includeDataType.integer
as allowable casting targets for booleans.doCast()
method to correctly cast boolean values to integers (1 fortrue
, 0 forfalse
).Why is this change necessary?
This change is necessary to ensure that
pg-mem
can emulate PostgreSQL as accurately as possible. The absence of this feature could lead to discrepancies between the behavior ofpg-mem
and PostgreSQL, especially when testing applications that depend on this particular casting behavior.How does it solve the problem?
The modifications to the
doCanCast()
anddoCast()
methods in theBoolType
class now allow for seamless casting from boolean to integer, emulating the same behavior in PostgreSQL.Examples
These SQL queries should now work with
pg-mem
: