Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a0cd991

Browse files
committed
Add int2-to-int8 and int8-to-int2 conversion routines. Needed to avoid
breaking existing pg_dump scripts, which try to assign the result of count(*) to an int2 variable. catversion bumped.
1 parent 92e8282 commit a0cd991

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

src/backend/utils/adt/int8.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.34 2001/10/25 05:49:44 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.35 2001/10/25 14:10:06 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -697,6 +697,29 @@ int84(PG_FUNCTION_ARGS)
697697
PG_RETURN_INT32(result);
698698
}
699699

700+
Datum
701+
int28(PG_FUNCTION_ARGS)
702+
{
703+
int16 val = PG_GETARG_INT16(0);
704+
705+
PG_RETURN_INT64((int64) val);
706+
}
707+
708+
Datum
709+
int82(PG_FUNCTION_ARGS)
710+
{
711+
int64 val = PG_GETARG_INT64(0);
712+
int16 result;
713+
714+
result = (int16) val;
715+
716+
/* Test for overflow by reverse-conversion. */
717+
if ((int64) result != val)
718+
elog(ERROR, "int8 conversion to int2 is out of range");
719+
720+
PG_RETURN_INT16(result);
721+
}
722+
700723
Datum
701724
i8tod(PG_FUNCTION_ARGS)
702725
{

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-2001, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $Id: catversion.h,v 1.100 2001/10/25 05:49:56 momjian Exp $
40+
* $Id: catversion.h,v 1.101 2001/10/25 14:10:06 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,5 +53,5 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 200110181
56+
#define CATALOG_VERSION_NO 200110251
5757
#endif

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-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_proc.h,v 1.218 2001/10/25 05:49:57 momjian Exp $
10+
* $Id: pg_proc.h,v 1.219 2001/10/25 14:10:06 tgl Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -885,6 +885,11 @@ DESCR("convert int8 to float8");
885885
DATA(insert OID = 483 ( int8 PGUID 12 f t t t 1 f 20 "701" 100 0 0 100 dtoi8 - ));
886886
DESCR("convert float8 to int8");
887887

888+
DATA(insert OID = 714 ( int2 PGUID 12 f t t t 1 f 21 "20" 100 0 0 100 int82 - ));
889+
DESCR("convert int8 to int2");
890+
DATA(insert OID = 754 ( int8 PGUID 12 f t t t 1 f 20 "21" 100 0 0 100 int28 - ));
891+
DESCR("convert int2 to int8");
892+
888893
/* OIDS 500 - 599 */
889894

890895
/* OIDS 600 - 699 */

src/include/utils/int8.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: int8.h,v 1.28 2001/10/25 05:50:10 momjian Exp $
10+
* $Id: int8.h,v 1.29 2001/10/25 14:10:07 tgl Exp $
1111
*
1212
* NOTES
1313
* These data types are supported on all 64-bit architectures, and may
@@ -98,6 +98,9 @@ extern Datum int48div(PG_FUNCTION_ARGS);
9898
extern Datum int48(PG_FUNCTION_ARGS);
9999
extern Datum int84(PG_FUNCTION_ARGS);
100100

101+
extern Datum int28(PG_FUNCTION_ARGS);
102+
extern Datum int82(PG_FUNCTION_ARGS);
103+
101104
extern Datum i8tod(PG_FUNCTION_ARGS);
102105
extern Datum dtoi8(PG_FUNCTION_ARGS);
103106

0 commit comments

Comments
 (0)