1998-07-08 15:57:05 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* int8.c
|
1998-07-08 15:57:05 +02:00
|
|
|
* Internal 64-bit integer operations
|
|
|
|
*
|
2001-01-24 20:43:33 +01:00
|
|
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
2000-05-28 19:56:29 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2002-02-23 02:01:30 +01:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.37 2002/02/23 01:01:30 momjian Exp $
|
2000-05-28 19:56:29 +02:00
|
|
|
*
|
1998-07-08 15:57:05 +02:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2000-07-13 00:59:15 +02:00
|
|
|
#include "postgres.h"
|
|
|
|
|
1998-07-08 15:57:05 +02:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <float.h>
|
1999-08-21 05:06:58 +02:00
|
|
|
#include <limits.h>
|
|
|
|
|
1998-07-08 15:57:05 +02:00
|
|
|
#include "utils/int8.h"
|
|
|
|
|
2001-08-24 16:07:50 +02:00
|
|
|
/* this should be set in pg_config.h, but just in case it wasn't: */
|
2000-05-28 19:56:29 +02:00
|
|
|
#ifndef INT64_FORMAT
|
|
|
|
#define INT64_FORMAT "%ld"
|
|
|
|
#endif
|
|
|
|
|
2001-11-24 20:57:06 +01:00
|
|
|
#ifdef HAVE_LL_CONSTANTS
|
|
|
|
#define INT64CONST(x) ((int64) x##LL)
|
|
|
|
#else
|
|
|
|
#define INT64CONST(x) ((int64) x)
|
|
|
|
#endif
|
|
|
|
|
1998-07-08 15:57:05 +02:00
|
|
|
#define MAXINT8LEN 25
|
|
|
|
|
1999-08-21 05:06:58 +02:00
|
|
|
#ifndef INT_MAX
|
|
|
|
#define INT_MAX (0x7FFFFFFFL)
|
|
|
|
#endif
|
|
|
|
#ifndef INT_MIN
|
|
|
|
#define INT_MIN (-INT_MAX-1)
|
|
|
|
#endif
|
|
|
|
#ifndef SHRT_MAX
|
|
|
|
#define SHRT_MAX (0x7FFF)
|
|
|
|
#endif
|
|
|
|
#ifndef SHRT_MIN
|
|
|
|
#define SHRT_MIN (-SHRT_MAX-1)
|
|
|
|
#endif
|
|
|
|
|
1998-07-08 15:57:05 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
**
|
|
|
|
** Routines for 64-bit integers.
|
|
|
|
**
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
/*----------------------------------------------------------
|
|
|
|
* Formatting and conversion routines.
|
|
|
|
*---------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* int8in()
|
|
|
|
*/
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int8in(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
char *str = PG_GETARG_CSTRING(0);
|
|
|
|
int64 result;
|
1999-02-03 01:18:53 +01:00
|
|
|
char *ptr = str;
|
|
|
|
int64 tmp = 0;
|
|
|
|
int sign = 1;
|
1998-07-08 15:57:05 +02:00
|
|
|
|
1999-05-25 18:15:34 +02:00
|
|
|
/*
|
|
|
|
* Do our own scan, rather than relying on sscanf which might be
|
2000-02-24 02:54:40 +01:00
|
|
|
* broken for long long.
|
1999-02-03 01:18:53 +01:00
|
|
|
*/
|
2001-10-25 07:50:21 +02:00
|
|
|
while (*ptr && isspace((unsigned char) *ptr)) /* skip leading spaces */
|
1999-02-03 01:18:53 +01:00
|
|
|
ptr++;
|
2001-11-24 20:57:06 +01:00
|
|
|
/* handle sign */
|
|
|
|
if (*ptr == '-')
|
|
|
|
{
|
|
|
|
ptr++;
|
|
|
|
sign = -1;
|
|
|
|
/*
|
|
|
|
* Do an explicit check for INT64_MIN. Ugly though this is, it's
|
|
|
|
* cleaner than trying to get the loop below to handle it portably.
|
|
|
|
*/
|
|
|
|
#ifndef INT64_IS_BUSTED
|
|
|
|
if (strcmp(ptr, "9223372036854775808") == 0)
|
|
|
|
{
|
|
|
|
result = - INT64CONST(0x7fffffffffffffff) - 1;
|
|
|
|
PG_RETURN_INT64(result);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
1999-02-03 01:18:53 +01:00
|
|
|
else if (*ptr == '+')
|
|
|
|
ptr++;
|
2001-03-22 05:01:46 +01:00
|
|
|
if (!isdigit((unsigned char) *ptr)) /* require at least one digit */
|
2000-02-24 02:54:40 +01:00
|
|
|
elog(ERROR, "Bad int8 external representation \"%s\"", str);
|
2001-03-22 05:01:46 +01:00
|
|
|
while (*ptr && isdigit((unsigned char) *ptr)) /* process digits */
|
2000-02-24 02:54:40 +01:00
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
int64 newtmp = tmp * 10 + (*ptr++ - '0');
|
2000-02-24 02:54:40 +01:00
|
|
|
|
|
|
|
if ((newtmp / 10) != tmp) /* overflow? */
|
2000-04-12 19:17:23 +02:00
|
|
|
elog(ERROR, "int8 value out of range: \"%s\"", str);
|
2000-02-24 02:54:40 +01:00
|
|
|
tmp = newtmp;
|
|
|
|
}
|
1999-05-25 18:15:34 +02:00
|
|
|
if (*ptr) /* trailing junk? */
|
2000-02-24 02:54:40 +01:00
|
|
|
elog(ERROR, "Bad int8 external representation \"%s\"", str);
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
result = (sign < 0) ? -tmp : tmp;
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_INT64(result);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* int8out()
|
|
|
|
*/
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int8out(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val = PG_GETARG_INT64(0);
|
1998-07-08 15:57:05 +02:00
|
|
|
char *result;
|
|
|
|
int len;
|
|
|
|
char buf[MAXINT8LEN + 1];
|
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
if ((len = snprintf(buf, MAXINT8LEN, INT64_FORMAT, val)) < 0)
|
1999-08-21 05:06:58 +02:00
|
|
|
elog(ERROR, "Unable to format int8");
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
result = pstrdup(buf);
|
|
|
|
PG_RETURN_CSTRING(result);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------
|
2000-07-28 07:07:49 +02:00
|
|
|
* Relational operators for int8s, including cross-data-type comparisons.
|
1998-07-08 15:57:05 +02:00
|
|
|
*---------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* int8relop()
|
|
|
|
* Is val1 relop val2?
|
|
|
|
*/
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int8eq(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
1999-08-21 05:06:58 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_BOOL(val1 == val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int8ne(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
1999-08-21 05:06:58 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_BOOL(val1 != val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int8lt(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
1999-08-21 05:06:58 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_BOOL(val1 < val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int8gt(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
1999-08-21 05:06:58 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_BOOL(val1 > val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int8le(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
1999-08-21 05:06:58 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_BOOL(val1 <= val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int8ge(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_BOOL(val1 >= val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
|
|
|
/* int84relop()
|
|
|
|
* Is 64-bit val1 relop 32-bit val2?
|
|
|
|
*/
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int84eq(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int32 val2 = PG_GETARG_INT32(1);
|
1999-08-21 05:06:58 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_BOOL(val1 == val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int84ne(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int32 val2 = PG_GETARG_INT32(1);
|
1999-08-21 05:06:58 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_BOOL(val1 != val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int84lt(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int32 val2 = PG_GETARG_INT32(1);
|
1999-08-21 05:06:58 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_BOOL(val1 < val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int84gt(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int32 val2 = PG_GETARG_INT32(1);
|
1999-08-21 05:06:58 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_BOOL(val1 > val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int84le(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int32 val2 = PG_GETARG_INT32(1);
|
1999-08-21 05:06:58 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_BOOL(val1 <= val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int84ge(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int32 val2 = PG_GETARG_INT32(1);
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_BOOL(val1 >= val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
|
|
|
/* int48relop()
|
|
|
|
* Is 32-bit val1 relop 64-bit val2?
|
|
|
|
*/
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int48eq(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int32 val1 = PG_GETARG_INT32(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
1999-08-21 05:06:58 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_BOOL(val1 == val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int48ne(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int32 val1 = PG_GETARG_INT32(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
1999-08-21 05:06:58 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_BOOL(val1 != val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int48lt(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int32 val1 = PG_GETARG_INT32(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
1999-08-21 05:06:58 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_BOOL(val1 < val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int48gt(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int32 val1 = PG_GETARG_INT32(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
1999-08-21 05:06:58 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_BOOL(val1 > val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int48le(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int32 val1 = PG_GETARG_INT32(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
1999-08-21 05:06:58 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_BOOL(val1 <= val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int48ge(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int32 val1 = PG_GETARG_INT32(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
2000-07-28 07:07:49 +02:00
|
|
|
|
|
|
|
PG_RETURN_BOOL(val1 >= val2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* int82relop()
|
|
|
|
* Is 64-bit val1 relop 16-bit val2?
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
int82eq(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int16 val2 = PG_GETARG_INT16(1);
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(val1 == val2);
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
int82ne(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int16 val2 = PG_GETARG_INT16(1);
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(val1 != val2);
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
int82lt(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int16 val2 = PG_GETARG_INT16(1);
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(val1 < val2);
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
int82gt(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int16 val2 = PG_GETARG_INT16(1);
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(val1 > val2);
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
int82le(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int16 val2 = PG_GETARG_INT16(1);
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(val1 <= val2);
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
int82ge(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int16 val2 = PG_GETARG_INT16(1);
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(val1 >= val2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* int28relop()
|
|
|
|
* Is 16-bit val1 relop 64-bit val2?
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
int28eq(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
int16 val1 = PG_GETARG_INT16(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(val1 == val2);
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
int28ne(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
int16 val1 = PG_GETARG_INT16(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(val1 != val2);
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
int28lt(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
int16 val1 = PG_GETARG_INT16(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(val1 < val2);
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
int28gt(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
int16 val1 = PG_GETARG_INT16(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(val1 > val2);
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
int28le(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
int16 val1 = PG_GETARG_INT16(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(val1 <= val2);
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
int28ge(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
int16 val1 = PG_GETARG_INT16(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
1999-08-21 05:06:58 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_BOOL(val1 >= val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------
|
|
|
|
* Arithmetic operators on 64-bit integers.
|
|
|
|
*---------------------------------------------------------*/
|
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int8um(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val = PG_GETARG_INT64(0);
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
PG_RETURN_INT64(-val);
|
2000-06-13 09:35:40 +02:00
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2001-06-07 02:09:32 +02:00
|
|
|
Datum
|
|
|
|
int8up(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
int64 val = PG_GETARG_INT64(0);
|
|
|
|
|
|
|
|
PG_RETURN_INT64(val);
|
|
|
|
}
|
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int8pl(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_INT64(val1 + val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int8mi(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_INT64(val1 - val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int8mul(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_INT64(val1 * val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int8div(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_INT64(val1 / val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-03-15 00:06:59 +01:00
|
|
|
/* int8abs()
|
|
|
|
* Absolute value
|
|
|
|
*/
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int8abs(PG_FUNCTION_ARGS)
|
2000-03-15 00:06:59 +01:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 arg1 = PG_GETARG_INT64(0);
|
2000-03-15 00:06:59 +01:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_INT64((arg1 < 0) ? -arg1 : arg1);
|
2000-03-15 00:06:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* int8mod()
|
|
|
|
* Modulo operation.
|
|
|
|
*/
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int8mod(PG_FUNCTION_ARGS)
|
2000-03-15 00:06:59 +01:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
|
|
|
int64 result;
|
2000-03-15 00:06:59 +01:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
result = val1 / val2;
|
|
|
|
result *= val2;
|
|
|
|
result = val1 - result;
|
2000-03-15 00:06:59 +01:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_INT64(result);
|
|
|
|
}
|
2000-03-15 00:06:59 +01:00
|
|
|
|
|
|
|
/* int8fac()
|
|
|
|
* Factorial
|
|
|
|
*/
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int8fac(PG_FUNCTION_ARGS)
|
2000-03-15 00:06:59 +01:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 arg1 = PG_GETARG_INT64(0);
|
|
|
|
int64 result;
|
2000-04-12 19:17:23 +02:00
|
|
|
int64 i;
|
2000-03-15 00:06:59 +01:00
|
|
|
|
2002-02-23 02:01:30 +01:00
|
|
|
if (arg1 == 0)
|
|
|
|
result = 1;
|
|
|
|
else if (arg1 < 1)
|
2000-06-13 09:35:40 +02:00
|
|
|
result = 0;
|
2000-03-15 00:06:59 +01:00
|
|
|
else
|
2000-06-13 09:35:40 +02:00
|
|
|
for (i = arg1, result = 1; i > 0; --i)
|
|
|
|
result *= i;
|
2000-03-15 00:06:59 +01:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_INT64(result);
|
2000-03-15 00:06:59 +01:00
|
|
|
}
|
|
|
|
|
2001-08-15 00:21:59 +02:00
|
|
|
Datum
|
|
|
|
int8inc(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
int64 arg = PG_GETARG_INT64(0);
|
|
|
|
|
|
|
|
PG_RETURN_INT64(arg + 1);
|
|
|
|
}
|
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int8larger(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
|
|
|
int64 result;
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
result = ((val1 > val2) ? val1 : val2);
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_INT64(result);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int8smaller(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
|
|
|
int64 result;
|
1998-09-01 06:40:42 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
result = ((val1 < val2) ? val1 : val2);
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_INT64(result);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int84pl(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int32 val2 = PG_GETARG_INT32(1);
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_INT64(val1 + val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int84mi(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int32 val2 = PG_GETARG_INT32(1);
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_INT64(val1 - val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int84mul(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int32 val2 = PG_GETARG_INT32(1);
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_INT64(val1 * val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int84div(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val1 = PG_GETARG_INT64(0);
|
|
|
|
int32 val2 = PG_GETARG_INT32(1);
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_INT64(val1 / val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int48pl(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int32 val1 = PG_GETARG_INT32(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_INT64(val1 + val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int48mi(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int32 val1 = PG_GETARG_INT32(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_INT64(val1 - val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int48mul(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int32 val1 = PG_GETARG_INT32(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_INT64(val1 * val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int48div(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int32 val1 = PG_GETARG_INT32(0);
|
|
|
|
int64 val2 = PG_GETARG_INT64(1);
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_INT64(val1 / val2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-10-24 22:16:48 +02:00
|
|
|
/* Binary arithmetics
|
|
|
|
*
|
|
|
|
* int8and - returns arg1 & arg2
|
|
|
|
* int8or - returns arg1 | arg2
|
|
|
|
* int8xor - returns arg1 # arg2
|
|
|
|
* int8not - returns ~arg1
|
|
|
|
* int8shl - returns arg1 << arg2
|
|
|
|
* int8shr - returns arg1 >> arg2
|
|
|
|
*/
|
|
|
|
|
|
|
|
Datum
|
|
|
|
int8and(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
int64 arg1 = PG_GETARG_INT64(0);
|
|
|
|
int64 arg2 = PG_GETARG_INT64(1);
|
|
|
|
|
|
|
|
PG_RETURN_INT64(arg1 & arg2);
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
int8or(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
int64 arg1 = PG_GETARG_INT64(0);
|
|
|
|
int64 arg2 = PG_GETARG_INT64(1);
|
|
|
|
|
|
|
|
PG_RETURN_INT64(arg1 | arg2);
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
int8xor(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
int64 arg1 = PG_GETARG_INT64(0);
|
|
|
|
int64 arg2 = PG_GETARG_INT64(1);
|
|
|
|
|
|
|
|
PG_RETURN_INT64(arg1 ^ arg2);
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
int8not(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
int64 arg1 = PG_GETARG_INT64(0);
|
|
|
|
|
|
|
|
PG_RETURN_INT64(~arg1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
int8shl(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
int64 arg1 = PG_GETARG_INT64(0);
|
|
|
|
int32 arg2 = PG_GETARG_INT32(1);
|
|
|
|
|
|
|
|
PG_RETURN_INT64(arg1 << arg2);
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
int8shr(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
int64 arg1 = PG_GETARG_INT64(0);
|
|
|
|
int32 arg2 = PG_GETARG_INT32(1);
|
|
|
|
|
|
|
|
PG_RETURN_INT64(arg1 >> arg2);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
|
|
|
/*----------------------------------------------------------
|
|
|
|
* Conversion operators.
|
|
|
|
*---------------------------------------------------------*/
|
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int48(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int32 val = PG_GETARG_INT32(0);
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_INT64((int64) val);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int84(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val = PG_GETARG_INT64(0);
|
1998-07-08 15:57:05 +02:00
|
|
|
int32 result;
|
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
result = (int32) val;
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2001-09-07 03:33:44 +02:00
|
|
|
/* Test for overflow by reverse-conversion. */
|
|
|
|
if ((int64) result != val)
|
|
|
|
elog(ERROR, "int8 conversion to int4 is out of range");
|
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_INT32(result);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2001-10-25 16:10:07 +02:00
|
|
|
Datum
|
|
|
|
int28(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
int16 val = PG_GETARG_INT16(0);
|
|
|
|
|
|
|
|
PG_RETURN_INT64((int64) val);
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
int82(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
int64 val = PG_GETARG_INT64(0);
|
|
|
|
int16 result;
|
|
|
|
|
|
|
|
result = (int16) val;
|
|
|
|
|
|
|
|
/* Test for overflow by reverse-conversion. */
|
|
|
|
if ((int64) result != val)
|
|
|
|
elog(ERROR, "int8 conversion to int2 is out of range");
|
|
|
|
|
|
|
|
PG_RETURN_INT16(result);
|
|
|
|
}
|
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
i8tod(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
int64 val = PG_GETARG_INT64(0);
|
|
|
|
float8 result;
|
1999-08-21 05:06:58 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
result = val;
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_FLOAT8(result);
|
|
|
|
}
|
1998-07-08 15:57:05 +02:00
|
|
|
|
|
|
|
/* dtoi8()
|
|
|
|
* Convert double float to 8-byte integer.
|
|
|
|
*/
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
dtoi8(PG_FUNCTION_ARGS)
|
1998-07-08 15:57:05 +02:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
float8 val = PG_GETARG_FLOAT8(0);
|
|
|
|
int64 result;
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2001-01-26 23:50:26 +01:00
|
|
|
/* Round val to nearest integer (but it's still in float form) */
|
|
|
|
val = rint(val);
|
2001-03-22 05:01:46 +01:00
|
|
|
|
2001-01-26 23:50:26 +01:00
|
|
|
/*
|
2001-03-22 05:01:46 +01:00
|
|
|
* Does it fit in an int64? Avoid assuming that we have handy
|
|
|
|
* constants defined for the range boundaries, instead test for
|
|
|
|
* overflow by reverse-conversion.
|
2001-01-26 23:50:26 +01:00
|
|
|
*/
|
2000-06-13 09:35:40 +02:00
|
|
|
result = (int64) val;
|
1998-07-08 15:57:05 +02:00
|
|
|
|
2001-01-26 23:50:26 +01:00
|
|
|
if ((float8) result != val)
|
|
|
|
elog(ERROR, "Floating point conversion to int8 is out of range");
|
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
PG_RETURN_INT64(result);
|
|
|
|
}
|
1999-02-13 05:22:34 +01:00
|
|
|
|
|
|
|
/* text_int8()
|
|
|
|
*/
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
text_int8(PG_FUNCTION_ARGS)
|
1999-02-13 05:22:34 +01:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
text *str = PG_GETARG_TEXT_P(0);
|
1999-02-13 05:22:34 +01:00
|
|
|
int len;
|
|
|
|
char *s;
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum result;
|
1999-02-13 05:22:34 +01:00
|
|
|
|
|
|
|
len = (VARSIZE(str) - VARHDRSZ);
|
1999-05-25 18:15:34 +02:00
|
|
|
s = palloc(len + 1);
|
2000-06-13 09:35:40 +02:00
|
|
|
memcpy(s, VARDATA(str), len);
|
1999-05-25 18:15:34 +02:00
|
|
|
*(s + len) = '\0';
|
1999-02-13 05:22:34 +01:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
result = DirectFunctionCall1(int8in, CStringGetDatum(s));
|
|
|
|
|
|
|
|
pfree(s);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
1999-02-13 05:22:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* int8_text()
|
|
|
|
*/
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
int8_text(PG_FUNCTION_ARGS)
|
1999-02-13 05:22:34 +01:00
|
|
|
{
|
2000-06-13 09:35:40 +02:00
|
|
|
/* val is int64, but easier to leave it as Datum */
|
|
|
|
Datum val = PG_GETARG_DATUM(0);
|
1999-02-13 05:22:34 +01:00
|
|
|
char *s;
|
2000-06-13 09:35:40 +02:00
|
|
|
int len;
|
|
|
|
text *result;
|
1999-02-13 05:22:34 +01:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
s = DatumGetCString(DirectFunctionCall1(int8out, val));
|
1999-02-13 05:22:34 +01:00
|
|
|
len = strlen(s);
|
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
result = (text *) palloc(VARHDRSZ + len);
|
1999-02-13 05:22:34 +01:00
|
|
|
|
2000-07-04 01:10:14 +02:00
|
|
|
VARATT_SIZEP(result) = len + VARHDRSZ;
|
2000-06-13 09:35:40 +02:00
|
|
|
memcpy(VARDATA(result), s, len);
|
1999-02-13 05:22:34 +01:00
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
pfree(s);
|
|
|
|
|
|
|
|
PG_RETURN_TEXT_P(result);
|
|
|
|
}
|