From 5285b3576316b6ff6cd02834b63f0a1f3f5b3e08 Mon Sep 17 00:00:00 2001 From: Neil Conway Date: Sun, 27 Feb 2005 08:31:30 +0000 Subject: Add explicit casts between int4 and boolean. Patch from Sean Chittenden, editorializing by Neil Conway. Catalog version bumped. --- src/backend/utils/adt/int.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/backend/utils/adt/int.c') diff --git a/src/backend/utils/adt/int.c b/src/backend/utils/adt/int.c index 7525b50bfec..db36ac963e1 100644 --- a/src/backend/utils/adt/int.c +++ b/src/backend/utils/adt/int.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/int.c,v 1.64 2004/12/31 22:01:22 pgsql Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/int.c,v 1.65 2005/02/27 08:31:30 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -361,6 +361,25 @@ text_int4(PG_FUNCTION_ARGS) return result; } +/* Cast int4 -> bool */ +Datum +int4_bool(PG_FUNCTION_ARGS) +{ + if (PG_GETARG_INT32(0) == 0) + PG_RETURN_BOOL(false); + else + PG_RETURN_BOOL(true); +} + +/* Cast bool -> int4 */ +Datum +bool_int4(PG_FUNCTION_ARGS) +{ + if (PG_GETARG_BOOL(0) == false) + PG_RETURN_INT32(0); + else + PG_RETURN_INT32(1); +} /* * ============================ -- cgit v1.2.3