Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5285b35

Browse files
author
Neil Conway
committed
Add explicit casts between int4 and boolean. Patch from Sean Chittenden,
editorializing by Neil Conway. Catalog version bumped.
1 parent2d22f16 commit5285b35

File tree

5 files changed

+36
-6
lines changed

5 files changed

+36
-6
lines changed

‎src/backend/utils/adt/int.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/int.c,v 1.64 2004/12/31 22:01:22 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/int.c,v 1.65 2005/02/27 08:31:30 neilc Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -361,6 +361,25 @@ text_int4(PG_FUNCTION_ARGS)
361361
returnresult;
362362
}
363363

364+
/* Cast int4 -> bool */
365+
Datum
366+
int4_bool(PG_FUNCTION_ARGS)
367+
{
368+
if (PG_GETARG_INT32(0)==0)
369+
PG_RETURN_BOOL(false);
370+
else
371+
PG_RETURN_BOOL(true);
372+
}
373+
374+
/* Cast bool -> int4 */
375+
Datum
376+
bool_int4(PG_FUNCTION_ARGS)
377+
{
378+
if (PG_GETARG_BOOL(0)== false)
379+
PG_RETURN_INT32(0);
380+
else
381+
PG_RETURN_INT32(1);
382+
}
364383

365384
/*
366385
*============================

‎src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.255 2005/02/26 18:43:34 tgl Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.256 2005/02/27 08:31:30 neilc Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO200502261
56+
#defineCATALOG_VERSION_NO200502271
5757

5858
#endif

‎src/include/catalog/pg_cast.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* Copyright (c) 2002-2005, PostgreSQL Global Development Group
1212
*
13-
* $PostgreSQL: pgsql/src/include/catalog/pg_cast.h,v 1.17 2005/01/01 05:43:09 momjian Exp $
13+
* $PostgreSQL: pgsql/src/include/catalog/pg_cast.h,v 1.18 2005/02/27 08:31:30 neilc Exp $
1414
*
1515
* NOTES
1616
* the genbki.sh script reads this file and generates .bki
@@ -101,6 +101,10 @@ DATA(insert ( 1700 23 1744 a ));
101101
DATA(insert (17007001745i ));
102102
DATA(insert (17007011746i ));
103103

104+
/* Allow explicit coercions between int4 and bool */
105+
DATA(insert (23162557e ));
106+
DATA(insert (16232558e ));
107+
104108
/*
105109
* OID category: allow implicit conversion from any integral type (including
106110
* int8, to support OID literals > 2G) to OID, as well as assignment coercion

‎src/include/catalog/pg_proc.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.350 2005/02/26 18:43:34 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.351 2005/02/27 08:31:30 neilc Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -3604,6 +3604,11 @@ DATA(insert OID = 2550 ( integer_pl_datePGNSP PGUID 14 f f t f i 2 1082 "23 1
36043604
DATA(insertOID=2556 (pg_tablespace_databasesPGNSPPGUID12fftts126"26"_null_pg_tablespace_databases-_null_));
36053605
DESCR("returns database oids in a tablespace");
36063606

3607+
DATA(insertOID=2557 (boolPGNSPPGUID12fftfi116"23"_null_int4_bool-_null_ ));
3608+
DESCR("convert int4 to boolean");
3609+
DATA(insertOID=2558 (int4PGNSPPGUID12fftfi123"16"_null_bool_int4-_null_ ));
3610+
DESCR("convert boolean to int4");
3611+
36073612

36083613
/*
36093614
* Symbolic values for provolatile column: these indicate whether the result

‎src/include/utils/builtins.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.252 2004/12/31 22:03:45 pgsql Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.253 2005/02/27 08:31:30 neilc Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -111,6 +111,8 @@ extern Datum i2toi4(PG_FUNCTION_ARGS);
111111
externDatumi4toi2(PG_FUNCTION_ARGS);
112112
externDatumint2_text(PG_FUNCTION_ARGS);
113113
externDatumtext_int2(PG_FUNCTION_ARGS);
114+
externDatumint4_bool(PG_FUNCTION_ARGS);
115+
externDatumbool_int4(PG_FUNCTION_ARGS);
114116
externDatumint4_text(PG_FUNCTION_ARGS);
115117
externDatumtext_int4(PG_FUNCTION_ARGS);
116118
externDatumint4eq(PG_FUNCTION_ARGS);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp