Add explicit casts between int4 and boolean. Patch from Sean Chittenden,
authorNeil Conway <[email protected]>
Sun, 27 Feb 2005 08:31:30 +0000 (08:31 +0000)
committerNeil Conway <[email protected]>
Sun, 27 Feb 2005 08:31:30 +0000 (08:31 +0000)
editorializing by Neil Conway. Catalog version bumped.

src/backend/utils/adt/int.c
src/include/catalog/catversion.h
src/include/catalog/pg_cast.h
src/include/catalog/pg_proc.h
src/include/utils/builtins.h

index 7525b50bfecb9de1bdb207157d71fd0e95daf97c..db36ac963e1e8d9a652040b7136150cd90a2fe8f 100644 (file)
@@ -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);
+}
 
 /*
  *             ============================
index ca44b24b2c4e4bed9e76b33d14e874858e6544f4..a8a698492b36985009ecbfb6f1712d14f4ffd643 100644 (file)
@@ -37,7 +37,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.255 2005/02/26 18:43:34 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.256 2005/02/27 08:31:30 neilc Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -53,6 +53,6 @@
  */
 
 /*                                                     yyyymmddN */
-#define CATALOG_VERSION_NO     200502261
+#define CATALOG_VERSION_NO     200502271
 
 #endif
index ce496a37c20cf30457623c0e34daa973aae32d5e..c9e3a89aee63daa3964472b2f9127fc25eb7cb38 100644 (file)
@@ -10,7 +10,7 @@
  *
  * Copyright (c) 2002-2005, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/include/catalog/pg_cast.h,v 1.17 2005/01/01 05:43:09 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/pg_cast.h,v 1.18 2005/02/27 08:31:30 neilc Exp $
  *
  * NOTES
  *       the genbki.sh script reads this file and generates .bki
@@ -101,6 +101,10 @@ DATA(insert ( 1700  23 1744 a ));
 DATA(insert ( 1700     700 1745 i ));
 DATA(insert ( 1700     701 1746 i ));
 
+/* Allow explicit coercions between int4 and bool */
+DATA(insert (  23      16  2557 e ));
+DATA(insert (  16      23  2558 e ));
+
 /*
  * OID category: allow implicit conversion from any integral type (including
  * int8, to support OID literals > 2G) to OID, as well as assignment coercion
index e456e96bba697b035f70a9d01f13aeee9df06de6..6fa89674a3d3e52f13fbff2cb86e2d47e607c3dc 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.350 2005/02/26 18:43:34 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.351 2005/02/27 08:31:30 neilc Exp $
  *
  * NOTES
  *       The script catalog/genbki.sh reads this file and generates .bki
@@ -3604,6 +3604,11 @@ DATA(insert OID = 2550 ( integer_pl_date                 PGNSP PGUID 14 f f t f i 2 1082 "23 1
 DATA(insert OID = 2556 ( pg_tablespace_databases       PGNSP PGUID 12 f f t t s 1 26 "26" _null_ pg_tablespace_databases - _null_));
 DESCR("returns database oids in a tablespace");
 
+DATA(insert OID = 2557 ( bool                             PGNSP PGUID 12 f f t f i 1  16 "23" _null_   int4_bool - _null_ ));
+DESCR("convert int4 to boolean");
+DATA(insert OID = 2558 ( int4                             PGNSP PGUID 12 f f t f i 1  23 "16" _null_   bool_int4 - _null_ ));
+DESCR("convert boolean to int4");
+
 
 /*
  * Symbolic values for provolatile column: these indicate whether the result
index 7de4ae5e3592a99a47bbcaf303a58b2a69e16d28..26edd72c37c1b8b1fff8d6faf50f19e95dc64a4c 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.252 2004/12/31 22:03:45 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.253 2005/02/27 08:31:30 neilc Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -111,6 +111,8 @@ extern Datum i2toi4(PG_FUNCTION_ARGS);
 extern Datum i4toi2(PG_FUNCTION_ARGS);
 extern Datum int2_text(PG_FUNCTION_ARGS);
 extern Datum text_int2(PG_FUNCTION_ARGS);
+extern Datum int4_bool(PG_FUNCTION_ARGS);
+extern Datum bool_int4(PG_FUNCTION_ARGS);
 extern Datum int4_text(PG_FUNCTION_ARGS);
 extern Datum text_int4(PG_FUNCTION_ARGS);
 extern Datum int4eq(PG_FUNCTION_ARGS);