Commit 1ebe1da2 authored by Tom Lane's avatar Tom Lane

bpchar, varchar, bytea, numeric are toastable --- if you initdb, which

I did not force.  I marked numeric as compressable-but-not-move-off-able,
partly to test that storage mode and partly because I've got doubts
that numerics are large enough to need external storage.
parent 20f6a1e5
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.72 2000/07/03 03:57:03 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.73 2000/07/29 03:26:40 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -240,12 +240,14 @@ CreateTrigger(CreateTrigStmt *stmt) ...@@ -240,12 +240,14 @@ CreateTrigger(CreateTrigStmt *stmt)
strcat(args, "\\000"); strcat(args, "\\000");
} }
values[Anum_pg_trigger_tgnargs - 1] = Int16GetDatum(nargs); values[Anum_pg_trigger_tgnargs - 1] = Int16GetDatum(nargs);
values[Anum_pg_trigger_tgargs - 1] = PointerGetDatum(byteain(args)); values[Anum_pg_trigger_tgargs - 1] = DirectFunctionCall1(byteain,
CStringGetDatum(args));
} }
else else
{ {
values[Anum_pg_trigger_tgnargs - 1] = Int16GetDatum(0); values[Anum_pg_trigger_tgnargs - 1] = Int16GetDatum(0);
values[Anum_pg_trigger_tgargs - 1] = PointerGetDatum(byteain("")); values[Anum_pg_trigger_tgargs - 1] = DirectFunctionCall1(byteain,
CStringGetDatum(""));
} }
MemSet(tgattr, 0, FUNC_MAX_ARGS * sizeof(int16)); MemSet(tgattr, 0, FUNC_MAX_ARGS * sizeof(int16));
values[Anum_pg_trigger_tgattr - 1] = PointerGetDatum(tgattr); values[Anum_pg_trigger_tgattr - 1] = PointerGetDatum(tgattr);
......
/* ----------------------------------------------------------------------- /* -----------------------------------------------------------------------
* formatting.c * formatting.c
* *
* $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.19 2000/07/05 23:11:35 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.20 2000/07/29 03:26:41 tgl Exp $
* *
* *
* Portions Copyright (c) 1999-2000, PostgreSQL, Inc * Portions Copyright (c) 1999-2000, PostgreSQL, Inc
...@@ -4066,7 +4066,9 @@ numeric_to_char(PG_FUNCTION_ARGS) ...@@ -4066,7 +4066,9 @@ numeric_to_char(PG_FUNCTION_ARGS)
x = DatumGetNumeric(DirectFunctionCall2(numeric_round, x = DatumGetNumeric(DirectFunctionCall2(numeric_round,
NumericGetDatum(value), NumericGetDatum(value),
Int32GetDatum(0))); Int32GetDatum(0)));
numstr = orgnum = int_to_roman(numeric_int4(x)); numstr = orgnum =
int_to_roman(DatumGetInt32(DirectFunctionCall1(numeric_int4,
NumericGetDatum(x))));
pfree(x); pfree(x);
} }
else else
...@@ -4080,8 +4082,12 @@ numeric_to_char(PG_FUNCTION_ARGS) ...@@ -4080,8 +4082,12 @@ numeric_to_char(PG_FUNCTION_ARGS)
Numeric b = DatumGetNumeric(DirectFunctionCall1(int4_numeric, Numeric b = DatumGetNumeric(DirectFunctionCall1(int4_numeric,
Int32GetDatum(Num.multi))); Int32GetDatum(Num.multi)));
x = numeric_power(a, b); x = DatumGetNumeric(DirectFunctionCall2(numeric_power,
val = numeric_mul(value, x); NumericGetDatum(a),
NumericGetDatum(b)));
val = DatumGetNumeric(DirectFunctionCall2(numeric_mul,
NumericGetDatum(value),
NumericGetDatum(x)));
pfree(x); pfree(x);
pfree(a); pfree(a);
pfree(b); pfree(b);
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* *
* 1998 Jan Wieck * 1998 Jan Wieck
* *
* $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.32 2000/07/17 03:05:18 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.33 2000/07/29 03:26:41 tgl Exp $
* *
* ---------- * ----------
*/ */
...@@ -351,25 +351,18 @@ numeric(PG_FUNCTION_ARGS) ...@@ -351,25 +351,18 @@ numeric(PG_FUNCTION_ARGS)
* ---------------------------------------------------------------------- * ----------------------------------------------------------------------
*/ */
Datum
Numeric numeric_abs(PG_FUNCTION_ARGS)
numeric_abs(Numeric num)
{ {
Numeric num = PG_GETARG_NUMERIC(0);
Numeric res; Numeric res;
/* ----------
* Handle NULL
* ----------
*/
if (num == NULL)
return NULL;
/* ---------- /* ----------
* Handle NaN * Handle NaN
* ---------- * ----------
*/ */
if (NUMERIC_IS_NAN(num)) if (NUMERIC_IS_NAN(num))
return make_result(&const_nan); PG_RETURN_NUMERIC(make_result(&const_nan));
/* ---------- /* ----------
* Do it the easy way directly on the packed format * Do it the easy way directly on the packed format
...@@ -380,28 +373,22 @@ numeric_abs(Numeric num) ...@@ -380,28 +373,22 @@ numeric_abs(Numeric num)
res->n_sign_dscale = NUMERIC_POS | NUMERIC_DSCALE(num); res->n_sign_dscale = NUMERIC_POS | NUMERIC_DSCALE(num);
return res; PG_RETURN_NUMERIC(res);
} }
Numeric Datum
numeric_uminus(Numeric num) numeric_uminus(PG_FUNCTION_ARGS)
{ {
Numeric num = PG_GETARG_NUMERIC(0);
Numeric res; Numeric res;
/* ----------
* Handle NULL
* ----------
*/
if (num == NULL)
return NULL;
/* ---------- /* ----------
* Handle NaN * Handle NaN
* ---------- * ----------
*/ */
if (NUMERIC_IS_NAN(num)) if (NUMERIC_IS_NAN(num))
return make_result(&const_nan); PG_RETURN_NUMERIC(make_result(&const_nan));
/* ---------- /* ----------
* Do it the easy way directly on the packed format * Do it the easy way directly on the packed format
...@@ -425,29 +412,23 @@ numeric_uminus(Numeric num) ...@@ -425,29 +412,23 @@ numeric_uminus(Numeric num)
res->n_sign_dscale = NUMERIC_POS | NUMERIC_DSCALE(num); res->n_sign_dscale = NUMERIC_POS | NUMERIC_DSCALE(num);
} }
return res; PG_RETURN_NUMERIC(res);
} }
Numeric Datum
numeric_sign(Numeric num) numeric_sign(PG_FUNCTION_ARGS)
{ {
Numeric num = PG_GETARG_NUMERIC(0);
Numeric res; Numeric res;
NumericVar result; NumericVar result;
/* ----------
* Handle NULL
* ----------
*/
if (num == NULL)
return NULL;
/* ---------- /* ----------
* Handle NaN * Handle NaN
* ---------- * ----------
*/ */
if (NUMERIC_IS_NAN(num)) if (NUMERIC_IS_NAN(num))
return make_result(&const_nan); PG_RETURN_NUMERIC(make_result(&const_nan));
init_var(&result); init_var(&result);
...@@ -473,7 +454,7 @@ numeric_sign(Numeric num) ...@@ -473,7 +454,7 @@ numeric_sign(Numeric num)
res = make_result(&result); res = make_result(&result);
free_var(&result); free_var(&result);
return res; PG_RETURN_NUMERIC(res);
} }
...@@ -633,17 +614,15 @@ numeric_trunc(PG_FUNCTION_ARGS) ...@@ -633,17 +614,15 @@ numeric_trunc(PG_FUNCTION_ARGS)
* Return the smallest integer greater than or equal to the argument * Return the smallest integer greater than or equal to the argument
* ---------- * ----------
*/ */
Numeric Datum
numeric_ceil(Numeric num) numeric_ceil(PG_FUNCTION_ARGS)
{ {
Numeric num = PG_GETARG_NUMERIC(0);
Numeric res; Numeric res;
NumericVar result; NumericVar result;
if (num == NULL)
return NULL;
if (NUMERIC_IS_NAN(num)) if (NUMERIC_IS_NAN(num))
return make_result(&const_nan); PG_RETURN_NUMERIC(make_result(&const_nan));
init_var(&result); init_var(&result);
...@@ -655,7 +634,7 @@ numeric_ceil(Numeric num) ...@@ -655,7 +634,7 @@ numeric_ceil(Numeric num)
res = make_result(&result); res = make_result(&result);
free_var(&result); free_var(&result);
return res; PG_RETURN_NUMERIC(res);
} }
...@@ -665,17 +644,15 @@ numeric_ceil(Numeric num) ...@@ -665,17 +644,15 @@ numeric_ceil(Numeric num)
* Return the largest integer equal to or less than the argument * Return the largest integer equal to or less than the argument
* ---------- * ----------
*/ */
Numeric Datum
numeric_floor(Numeric num) numeric_floor(PG_FUNCTION_ARGS)
{ {
Numeric num = PG_GETARG_NUMERIC(0);
Numeric res; Numeric res;
NumericVar result; NumericVar result;
if (num == NULL)
return NULL;
if (NUMERIC_IS_NAN(num)) if (NUMERIC_IS_NAN(num))
return make_result(&const_nan); PG_RETURN_NUMERIC(make_result(&const_nan));
init_var(&result); init_var(&result);
...@@ -687,7 +664,7 @@ numeric_floor(Numeric num) ...@@ -687,7 +664,7 @@ numeric_floor(Numeric num)
res = make_result(&result); res = make_result(&result);
free_var(&result); free_var(&result);
return res; PG_RETURN_NUMERIC(res);
} }
...@@ -695,203 +672,236 @@ numeric_floor(Numeric num) ...@@ -695,203 +672,236 @@ numeric_floor(Numeric num)
* *
* Comparison functions * Comparison functions
* *
* Note: btree indexes need these routines not to leak memory; therefore,
* be careful to free working copies of toasted datums. Most places don't
* need to be so careful.
* ---------------------------------------------------------------------- * ----------------------------------------------------------------------
*/ */
int32 Datum
numeric_cmp(Numeric num1, Numeric num2) numeric_cmp(PG_FUNCTION_ARGS)
{ {
Numeric num1 = PG_GETARG_NUMERIC(0);
Numeric num2 = PG_GETARG_NUMERIC(1);
int result; int result;
NumericVar arg1;
NumericVar arg2;
if (num1 == NULL || num2 == NULL)
return (int32) 0;
if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2)) if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
return (int32) 0; result = 0;
else
{
NumericVar arg1;
NumericVar arg2;
init_var(&arg1); init_var(&arg1);
init_var(&arg2); init_var(&arg2);
set_var_from_num(num1, &arg1); set_var_from_num(num1, &arg1);
set_var_from_num(num2, &arg2); set_var_from_num(num2, &arg2);
result = cmp_var(&arg1, &arg2); result = cmp_var(&arg1, &arg2);
free_var(&arg1); free_var(&arg1);
free_var(&arg2); free_var(&arg2);
}
PG_FREE_IF_COPY(num1, 0);
PG_FREE_IF_COPY(num2, 1);
return (int32) ((result == 0) ? 0 : ((result < 0) ? -1 : 1)); PG_RETURN_INT32(result);
} }
bool Datum
numeric_eq(Numeric num1, Numeric num2) numeric_eq(PG_FUNCTION_ARGS)
{ {
int result; Numeric num1 = PG_GETARG_NUMERIC(0);
NumericVar arg1; Numeric num2 = PG_GETARG_NUMERIC(1);
NumericVar arg2; bool result;
if (num1 == NULL || num2 == NULL)
return FALSE;
if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2)) if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
return FALSE; result = false;
else
{
NumericVar arg1;
NumericVar arg2;
init_var(&arg1); init_var(&arg1);
init_var(&arg2); init_var(&arg2);
set_var_from_num(num1, &arg1); set_var_from_num(num1, &arg1);
set_var_from_num(num2, &arg2); set_var_from_num(num2, &arg2);
result = cmp_var(&arg1, &arg2); result = cmp_var(&arg1, &arg2) == 0;
free_var(&arg1); free_var(&arg1);
free_var(&arg2); free_var(&arg2);
}
return (result == 0); PG_FREE_IF_COPY(num1, 0);
} PG_FREE_IF_COPY(num2, 1);
PG_RETURN_BOOL(result);
}
bool Datum
numeric_ne(Numeric num1, Numeric num2) numeric_ne(PG_FUNCTION_ARGS)
{ {
int result; Numeric num1 = PG_GETARG_NUMERIC(0);
NumericVar arg1; Numeric num2 = PG_GETARG_NUMERIC(1);
NumericVar arg2; bool result;
if (num1 == NULL || num2 == NULL)
return FALSE;
if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2)) if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
return FALSE; result = false;
else
{
NumericVar arg1;
NumericVar arg2;
init_var(&arg1); init_var(&arg1);
init_var(&arg2); init_var(&arg2);
set_var_from_num(num1, &arg1); set_var_from_num(num1, &arg1);
set_var_from_num(num2, &arg2); set_var_from_num(num2, &arg2);
result = cmp_var(&arg1, &arg2); result = cmp_var(&arg1, &arg2) != 0;
free_var(&arg1); free_var(&arg1);
free_var(&arg2); free_var(&arg2);
}
return (result != 0); PG_FREE_IF_COPY(num1, 0);
} PG_FREE_IF_COPY(num2, 1);
PG_RETURN_BOOL(result);
}
bool Datum
numeric_gt(Numeric num1, Numeric num2) numeric_gt(PG_FUNCTION_ARGS)
{ {
int result; Numeric num1 = PG_GETARG_NUMERIC(0);
NumericVar arg1; Numeric num2 = PG_GETARG_NUMERIC(1);
NumericVar arg2; bool result;
if (num1 == NULL || num2 == NULL)
return FALSE;
if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2)) if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
return FALSE; result = false;
else
{
NumericVar arg1;
NumericVar arg2;
init_var(&arg1); init_var(&arg1);
init_var(&arg2); init_var(&arg2);
set_var_from_num(num1, &arg1); set_var_from_num(num1, &arg1);
set_var_from_num(num2, &arg2); set_var_from_num(num2, &arg2);
result = cmp_var(&arg1, &arg2); result = cmp_var(&arg1, &arg2) > 0;
free_var(&arg1); free_var(&arg1);
free_var(&arg2); free_var(&arg2);
}
return (result > 0); PG_FREE_IF_COPY(num1, 0);
} PG_FREE_IF_COPY(num2, 1);
PG_RETURN_BOOL(result);
}
bool Datum
numeric_ge(Numeric num1, Numeric num2) numeric_ge(PG_FUNCTION_ARGS)
{ {
int result; Numeric num1 = PG_GETARG_NUMERIC(0);
NumericVar arg1; Numeric num2 = PG_GETARG_NUMERIC(1);
NumericVar arg2; bool result;
if (num1 == NULL || num2 == NULL)
return FALSE;
if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2)) if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
return FALSE; result = false;
else
{
NumericVar arg1;
NumericVar arg2;
init_var(&arg1); init_var(&arg1);
init_var(&arg2); init_var(&arg2);
set_var_from_num(num1, &arg1); set_var_from_num(num1, &arg1);
set_var_from_num(num2, &arg2); set_var_from_num(num2, &arg2);
result = cmp_var(&arg1, &arg2); result = cmp_var(&arg1, &arg2) >= 0;
free_var(&arg1); free_var(&arg1);
free_var(&arg2); free_var(&arg2);
}
return (result >= 0); PG_FREE_IF_COPY(num1, 0);
} PG_FREE_IF_COPY(num2, 1);
PG_RETURN_BOOL(result);
}
bool Datum
numeric_lt(Numeric num1, Numeric num2) numeric_lt(PG_FUNCTION_ARGS)
{ {
int result; Numeric num1 = PG_GETARG_NUMERIC(0);
NumericVar arg1; Numeric num2 = PG_GETARG_NUMERIC(1);
NumericVar arg2; bool result;
if (num1 == NULL || num2 == NULL)
return FALSE;
if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2)) if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
return FALSE; result = false;
else
{
NumericVar arg1;
NumericVar arg2;
init_var(&arg1); init_var(&arg1);
init_var(&arg2); init_var(&arg2);
set_var_from_num(num1, &arg1); set_var_from_num(num1, &arg1);
set_var_from_num(num2, &arg2); set_var_from_num(num2, &arg2);
result = cmp_var(&arg1, &arg2); result = cmp_var(&arg1, &arg2) < 0;
free_var(&arg1); free_var(&arg1);
free_var(&arg2); free_var(&arg2);
}
return (result < 0); PG_FREE_IF_COPY(num1, 0);
} PG_FREE_IF_COPY(num2, 1);
PG_RETURN_BOOL(result);
}
bool Datum
numeric_le(Numeric num1, Numeric num2) numeric_le(PG_FUNCTION_ARGS)
{ {
int result; Numeric num1 = PG_GETARG_NUMERIC(0);
NumericVar arg1; Numeric num2 = PG_GETARG_NUMERIC(1);
NumericVar arg2; bool result;
if (num1 == NULL || num2 == NULL)
return FALSE;
if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2)) if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
return FALSE; result = false;
else
{
NumericVar arg1;
NumericVar arg2;
init_var(&arg1); init_var(&arg1);
init_var(&arg2); init_var(&arg2);
set_var_from_num(num1, &arg1); set_var_from_num(num1, &arg1);
set_var_from_num(num2, &arg2); set_var_from_num(num2, &arg2);
result = cmp_var(&arg1, &arg2); result = cmp_var(&arg1, &arg2) <= 0;
free_var(&arg1); free_var(&arg1);
free_var(&arg2); free_var(&arg2);
}
return (result <= 0); PG_FREE_IF_COPY(num1, 0);
PG_FREE_IF_COPY(num2, 1);
PG_RETURN_BOOL(result);
} }
...@@ -909,27 +919,22 @@ numeric_le(Numeric num1, Numeric num2) ...@@ -909,27 +919,22 @@ numeric_le(Numeric num1, Numeric num2)
* Add two numerics * Add two numerics
* ---------- * ----------
*/ */
Numeric Datum
numeric_add(Numeric num1, Numeric num2) numeric_add(PG_FUNCTION_ARGS)
{ {
Numeric num1 = PG_GETARG_NUMERIC(0);
Numeric num2 = PG_GETARG_NUMERIC(1);
NumericVar arg1; NumericVar arg1;
NumericVar arg2; NumericVar arg2;
NumericVar result; NumericVar result;
Numeric res; Numeric res;
/* ----------
* Handle NULL
* ----------
*/
if (num1 == NULL || num2 == NULL)
return NULL;
/* ---------- /* ----------
* Handle NaN * Handle NaN
* ---------- * ----------
*/ */
if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2)) if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
return make_result(&const_nan); PG_RETURN_NUMERIC(make_result(&const_nan));
/* ---------- /* ----------
* Unpack the values, let add_var() compute the result * Unpack the values, let add_var() compute the result
...@@ -951,7 +956,7 @@ numeric_add(Numeric num1, Numeric num2) ...@@ -951,7 +956,7 @@ numeric_add(Numeric num1, Numeric num2)
free_var(&arg2); free_var(&arg2);
free_var(&result); free_var(&result);
return res; PG_RETURN_NUMERIC(res);
} }
...@@ -961,27 +966,22 @@ numeric_add(Numeric num1, Numeric num2) ...@@ -961,27 +966,22 @@ numeric_add(Numeric num1, Numeric num2)
* Subtract one numeric from another * Subtract one numeric from another
* ---------- * ----------
*/ */
Numeric Datum
numeric_sub(Numeric num1, Numeric num2) numeric_sub(PG_FUNCTION_ARGS)
{ {
Numeric num1 = PG_GETARG_NUMERIC(0);
Numeric num2 = PG_GETARG_NUMERIC(1);
NumericVar arg1; NumericVar arg1;
NumericVar arg2; NumericVar arg2;
NumericVar result; NumericVar result;
Numeric res; Numeric res;
/* ----------
* Handle NULL
* ----------
*/
if (num1 == NULL || num2 == NULL)
return NULL;
/* ---------- /* ----------
* Handle NaN * Handle NaN
* ---------- * ----------
*/ */
if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2)) if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
return make_result(&const_nan); PG_RETURN_NUMERIC(make_result(&const_nan));
/* ---------- /* ----------
* Unpack the two arguments, let sub_var() compute the * Unpack the two arguments, let sub_var() compute the
...@@ -1002,7 +1002,7 @@ numeric_sub(Numeric num1, Numeric num2) ...@@ -1002,7 +1002,7 @@ numeric_sub(Numeric num1, Numeric num2)
free_var(&arg2); free_var(&arg2);
free_var(&result); free_var(&result);
return res; PG_RETURN_NUMERIC(res);
} }
...@@ -1012,27 +1012,22 @@ numeric_sub(Numeric num1, Numeric num2) ...@@ -1012,27 +1012,22 @@ numeric_sub(Numeric num1, Numeric num2)
* Calculate the product of two numerics * Calculate the product of two numerics
* ---------- * ----------
*/ */
Numeric Datum
numeric_mul(Numeric num1, Numeric num2) numeric_mul(PG_FUNCTION_ARGS)
{ {
Numeric num1 = PG_GETARG_NUMERIC(0);
Numeric num2 = PG_GETARG_NUMERIC(1);
NumericVar arg1; NumericVar arg1;
NumericVar arg2; NumericVar arg2;
NumericVar result; NumericVar result;
Numeric res; Numeric res;
/* ----------
* Handle NULL
* ----------
*/
if (num1 == NULL || num2 == NULL)
return NULL;
/* ---------- /* ----------
* Handle NaN * Handle NaN
* ---------- * ----------
*/ */
if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2)) if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
return make_result(&const_nan); PG_RETURN_NUMERIC(make_result(&const_nan));
/* ---------- /* ----------
* Unpack the arguments, let mul_var() compute the result * Unpack the arguments, let mul_var() compute the result
...@@ -1063,7 +1058,7 @@ numeric_mul(Numeric num1, Numeric num2) ...@@ -1063,7 +1058,7 @@ numeric_mul(Numeric num1, Numeric num2)
free_var(&arg2); free_var(&arg2);
free_var(&result); free_var(&result);
return res; PG_RETURN_NUMERIC(res);
} }
...@@ -1073,28 +1068,23 @@ numeric_mul(Numeric num1, Numeric num2) ...@@ -1073,28 +1068,23 @@ numeric_mul(Numeric num1, Numeric num2)
* Divide one numeric into another * Divide one numeric into another
* ---------- * ----------
*/ */
Numeric Datum
numeric_div(Numeric num1, Numeric num2) numeric_div(PG_FUNCTION_ARGS)
{ {
Numeric num1 = PG_GETARG_NUMERIC(0);
Numeric num2 = PG_GETARG_NUMERIC(1);
NumericVar arg1; NumericVar arg1;
NumericVar arg2; NumericVar arg2;
NumericVar result; NumericVar result;
Numeric res; Numeric res;
int res_dscale; int res_dscale;
/* ----------
* Handle NULL
* ----------
*/
if (num1 == NULL || num2 == NULL)
return NULL;
/* ---------- /* ----------
* Handle NaN * Handle NaN
* ---------- * ----------
*/ */
if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2)) if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
return make_result(&const_nan); PG_RETURN_NUMERIC(make_result(&const_nan));
/* ---------- /* ----------
* Unpack the arguments * Unpack the arguments
...@@ -1144,7 +1134,7 @@ numeric_div(Numeric num1, Numeric num2) ...@@ -1144,7 +1134,7 @@ numeric_div(Numeric num1, Numeric num2)
free_var(&arg2); free_var(&arg2);
free_var(&result); free_var(&result);
return res; PG_RETURN_NUMERIC(res);
} }
...@@ -1154,19 +1144,18 @@ numeric_div(Numeric num1, Numeric num2) ...@@ -1154,19 +1144,18 @@ numeric_div(Numeric num1, Numeric num2)
* Calculate the modulo of two numerics * Calculate the modulo of two numerics
* ---------- * ----------
*/ */
Numeric Datum
numeric_mod(Numeric num1, Numeric num2) numeric_mod(PG_FUNCTION_ARGS)
{ {
Numeric num1 = PG_GETARG_NUMERIC(0);
Numeric num2 = PG_GETARG_NUMERIC(1);
Numeric res; Numeric res;
NumericVar arg1; NumericVar arg1;
NumericVar arg2; NumericVar arg2;
NumericVar result; NumericVar result;
if (num1 == NULL || num2 == NULL)
return NULL;
if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2)) if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
return make_result(&const_nan); PG_RETURN_NUMERIC(make_result(&const_nan));
init_var(&arg1); init_var(&arg1);
init_var(&arg2); init_var(&arg2);
...@@ -1184,7 +1173,7 @@ numeric_mod(Numeric num1, Numeric num2) ...@@ -1184,7 +1173,7 @@ numeric_mod(Numeric num1, Numeric num2)
free_var(&arg2); free_var(&arg2);
free_var(&arg1); free_var(&arg1);
return res; PG_RETURN_NUMERIC(res);
} }
...@@ -1194,25 +1183,19 @@ numeric_mod(Numeric num1, Numeric num2) ...@@ -1194,25 +1183,19 @@ numeric_mod(Numeric num1, Numeric num2)
* Increment a number by one * Increment a number by one
* ---------- * ----------
*/ */
Numeric Datum
numeric_inc(Numeric num) numeric_inc(PG_FUNCTION_ARGS)
{ {
Numeric num = PG_GETARG_NUMERIC(0);
NumericVar arg; NumericVar arg;
Numeric res; Numeric res;
/* ----------
* Handle NULL
* ----------
*/
if (num == NULL)
return NULL;
/* ---------- /* ----------
* Handle NaN * Handle NaN
* ---------- * ----------
*/ */
if (NUMERIC_IS_NAN(num)) if (NUMERIC_IS_NAN(num))
return make_result(&const_nan); PG_RETURN_NUMERIC(make_result(&const_nan));
/* ---------- /* ----------
* Compute the result and return it * Compute the result and return it
...@@ -1227,7 +1210,7 @@ numeric_inc(Numeric num) ...@@ -1227,7 +1210,7 @@ numeric_inc(Numeric num)
free_var(&arg); free_var(&arg);
return res; PG_RETURN_NUMERIC(res);
} }
...@@ -1237,26 +1220,21 @@ numeric_inc(Numeric num) ...@@ -1237,26 +1220,21 @@ numeric_inc(Numeric num)
* Return the smaller of two numbers * Return the smaller of two numbers
* ---------- * ----------
*/ */
Numeric Datum
numeric_smaller(Numeric num1, Numeric num2) numeric_smaller(PG_FUNCTION_ARGS)
{ {
Numeric num1 = PG_GETARG_NUMERIC(0);
Numeric num2 = PG_GETARG_NUMERIC(1);
NumericVar arg1; NumericVar arg1;
NumericVar arg2; NumericVar arg2;
Numeric res; Numeric res;
/* ----------
* Handle NULL
* ----------
*/
if (num1 == NULL || num2 == NULL)
return NULL;
/* ---------- /* ----------
* Handle NaN * Handle NaN
* ---------- * ----------
*/ */
if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2)) if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
return make_result(&const_nan); PG_RETURN_NUMERIC(make_result(&const_nan));
/* ---------- /* ----------
* Unpack the values, and decide which is the smaller one * Unpack the values, and decide which is the smaller one
...@@ -1276,7 +1254,7 @@ numeric_smaller(Numeric num1, Numeric num2) ...@@ -1276,7 +1254,7 @@ numeric_smaller(Numeric num1, Numeric num2)
free_var(&arg1); free_var(&arg1);
free_var(&arg2); free_var(&arg2);
return res; PG_RETURN_NUMERIC(res);
} }
...@@ -1286,26 +1264,21 @@ numeric_smaller(Numeric num1, Numeric num2) ...@@ -1286,26 +1264,21 @@ numeric_smaller(Numeric num1, Numeric num2)
* Return the larger of two numbers * Return the larger of two numbers
* ---------- * ----------
*/ */
Numeric Datum
numeric_larger(Numeric num1, Numeric num2) numeric_larger(PG_FUNCTION_ARGS)
{ {
Numeric num1 = PG_GETARG_NUMERIC(0);
Numeric num2 = PG_GETARG_NUMERIC(1);
NumericVar arg1; NumericVar arg1;
NumericVar arg2; NumericVar arg2;
Numeric res; Numeric res;
/* ----------
* Handle NULL
* ----------
*/
if (num1 == NULL || num2 == NULL)
return NULL;
/* ---------- /* ----------
* Handle NaN * Handle NaN
* ---------- * ----------
*/ */
if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2)) if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
return make_result(&const_nan); PG_RETURN_NUMERIC(make_result(&const_nan));
/* ---------- /* ----------
* Unpack the values, and decide which is the larger one * Unpack the values, and decide which is the larger one
...@@ -1325,7 +1298,7 @@ numeric_larger(Numeric num1, Numeric num2) ...@@ -1325,7 +1298,7 @@ numeric_larger(Numeric num1, Numeric num2)
free_var(&arg1); free_var(&arg1);
free_var(&arg2); free_var(&arg2);
return res; PG_RETURN_NUMERIC(res);
} }
...@@ -1343,27 +1316,21 @@ numeric_larger(Numeric num1, Numeric num2) ...@@ -1343,27 +1316,21 @@ numeric_larger(Numeric num1, Numeric num2)
* Compute the square root of a numeric. * Compute the square root of a numeric.
* ---------- * ----------
*/ */
Numeric Datum
numeric_sqrt(Numeric num) numeric_sqrt(PG_FUNCTION_ARGS)
{ {
Numeric num = PG_GETARG_NUMERIC(0);
Numeric res; Numeric res;
NumericVar arg; NumericVar arg;
NumericVar result; NumericVar result;
int res_dscale; int res_dscale;
/* ----------
* Handle NULL
* ----------
*/
if (num == NULL)
return NULL;
/* ---------- /* ----------
* Handle NaN * Handle NaN
* ---------- * ----------
*/ */
if (NUMERIC_IS_NAN(num)) if (NUMERIC_IS_NAN(num))
return make_result(&const_nan); PG_RETURN_NUMERIC(make_result(&const_nan));
/* ---------- /* ----------
* Unpack the argument, determine the scales like for divide, * Unpack the argument, determine the scales like for divide,
...@@ -1390,7 +1357,7 @@ numeric_sqrt(Numeric num) ...@@ -1390,7 +1357,7 @@ numeric_sqrt(Numeric num)
free_var(&result); free_var(&result);
free_var(&arg); free_var(&arg);
return res; PG_RETURN_NUMERIC(res);
} }
...@@ -1400,27 +1367,21 @@ numeric_sqrt(Numeric num) ...@@ -1400,27 +1367,21 @@ numeric_sqrt(Numeric num)
* Raise e to the power of x * Raise e to the power of x
* ---------- * ----------
*/ */
Numeric Datum
numeric_exp(Numeric num) numeric_exp(PG_FUNCTION_ARGS)
{ {
Numeric num = PG_GETARG_NUMERIC(0);
Numeric res; Numeric res;
NumericVar arg; NumericVar arg;
NumericVar result; NumericVar result;
int res_dscale; int res_dscale;
/* ----------
* Handle NULL
* ----------
*/
if (num == NULL)
return NULL;
/* ---------- /* ----------
* Handle NaN * Handle NaN
* ---------- * ----------
*/ */
if (NUMERIC_IS_NAN(num)) if (NUMERIC_IS_NAN(num))
return make_result(&const_nan); PG_RETURN_NUMERIC(make_result(&const_nan));
/* ---------- /* ----------
* Same procedure like for sqrt(). * Same procedure like for sqrt().
...@@ -1445,7 +1406,7 @@ numeric_exp(Numeric num) ...@@ -1445,7 +1406,7 @@ numeric_exp(Numeric num)
free_var(&result); free_var(&result);
free_var(&arg); free_var(&arg);
return res; PG_RETURN_NUMERIC(res);
} }
...@@ -1455,27 +1416,21 @@ numeric_exp(Numeric num) ...@@ -1455,27 +1416,21 @@ numeric_exp(Numeric num)
* Compute the natural logarithm of x * Compute the natural logarithm of x
* ---------- * ----------
*/ */
Numeric Datum
numeric_ln(Numeric num) numeric_ln(PG_FUNCTION_ARGS)
{ {
Numeric num = PG_GETARG_NUMERIC(0);
Numeric res; Numeric res;
NumericVar arg; NumericVar arg;
NumericVar result; NumericVar result;
int res_dscale; int res_dscale;
/* ----------
* Handle NULL
* ----------
*/
if (num == NULL)
return NULL;
/* ---------- /* ----------
* Handle NaN * Handle NaN
* ---------- * ----------
*/ */
if (NUMERIC_IS_NAN(num)) if (NUMERIC_IS_NAN(num))
return make_result(&const_nan); PG_RETURN_NUMERIC(make_result(&const_nan));
/* ---------- /* ----------
* Same procedure like for sqrt() * Same procedure like for sqrt()
...@@ -1500,7 +1455,7 @@ numeric_ln(Numeric num) ...@@ -1500,7 +1455,7 @@ numeric_ln(Numeric num)
free_var(&result); free_var(&result);
free_var(&arg); free_var(&arg);
return res; PG_RETURN_NUMERIC(res);
} }
...@@ -1510,28 +1465,23 @@ numeric_ln(Numeric num) ...@@ -1510,28 +1465,23 @@ numeric_ln(Numeric num)
* Compute the logarithm of x in a given base * Compute the logarithm of x in a given base
* ---------- * ----------
*/ */
Numeric Datum
numeric_log(Numeric num1, Numeric num2) numeric_log(PG_FUNCTION_ARGS)
{ {
Numeric num1 = PG_GETARG_NUMERIC(0);
Numeric num2 = PG_GETARG_NUMERIC(1);
Numeric res; Numeric res;
NumericVar arg1; NumericVar arg1;
NumericVar arg2; NumericVar arg2;
NumericVar result; NumericVar result;
int res_dscale; int res_dscale;
/* ----------
* Handle NULL
* ----------
*/
if (num1 == NULL || num2 == NULL)
return NULL;
/* ---------- /* ----------
* Handle NaN * Handle NaN
* ---------- * ----------
*/ */
if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2)) if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
return make_result(&const_nan); PG_RETURN_NUMERIC(make_result(&const_nan));
/* ---------- /* ----------
* Initialize things and calculate scales * Initialize things and calculate scales
...@@ -1563,7 +1513,7 @@ numeric_log(Numeric num1, Numeric num2) ...@@ -1563,7 +1513,7 @@ numeric_log(Numeric num1, Numeric num2)
free_var(&arg2); free_var(&arg2);
free_var(&arg1); free_var(&arg1);
return res; PG_RETURN_NUMERIC(res);
} }
...@@ -1573,28 +1523,23 @@ numeric_log(Numeric num1, Numeric num2) ...@@ -1573,28 +1523,23 @@ numeric_log(Numeric num1, Numeric num2)
* Raise m to the power of x * Raise m to the power of x
* ---------- * ----------
*/ */
Numeric Datum
numeric_power(Numeric num1, Numeric num2) numeric_power(PG_FUNCTION_ARGS)
{ {
Numeric num1 = PG_GETARG_NUMERIC(0);
Numeric num2 = PG_GETARG_NUMERIC(1);
Numeric res; Numeric res;
NumericVar arg1; NumericVar arg1;
NumericVar arg2; NumericVar arg2;
NumericVar result; NumericVar result;
int res_dscale; int res_dscale;
/* ----------
* Handle NULL
* ----------
*/
if (num1 == NULL || num2 == NULL)
return NULL;
/* ---------- /* ----------
* Handle NaN * Handle NaN
* ---------- * ----------
*/ */
if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2)) if (NUMERIC_IS_NAN(num1) || NUMERIC_IS_NAN(num2))
return make_result(&const_nan); PG_RETURN_NUMERIC(make_result(&const_nan));
/* ---------- /* ----------
* Initialize things and calculate scales * Initialize things and calculate scales
...@@ -1626,7 +1571,7 @@ numeric_power(Numeric num1, Numeric num2) ...@@ -1626,7 +1571,7 @@ numeric_power(Numeric num1, Numeric num2)
free_var(&arg2); free_var(&arg2);
free_var(&arg1); free_var(&arg1);
return res; PG_RETURN_NUMERIC(res);
} }
...@@ -1660,16 +1605,15 @@ int4_numeric(PG_FUNCTION_ARGS) ...@@ -1660,16 +1605,15 @@ int4_numeric(PG_FUNCTION_ARGS)
} }
int32 Datum
numeric_int4(Numeric num) numeric_int4(PG_FUNCTION_ARGS)
{ {
Numeric num = PG_GETARG_NUMERIC(0);
NumericVar x; NumericVar x;
char *str; char *str;
Datum result; Datum result;
if (num == NULL) /* XXX would it be better to return NULL? */
return 0;
if (NUMERIC_IS_NAN(num)) if (NUMERIC_IS_NAN(num))
elog(ERROR, "Cannot convert NaN to int4"); elog(ERROR, "Cannot convert NaN to int4");
...@@ -1687,7 +1631,7 @@ numeric_int4(Numeric num) ...@@ -1687,7 +1631,7 @@ numeric_int4(Numeric num)
result = DirectFunctionCall1(int4in, CStringGetDatum(str)); result = DirectFunctionCall1(int4in, CStringGetDatum(str));
pfree(str); pfree(str);
return result; PG_RETURN_DATUM(result);
} }
...@@ -1712,16 +1656,15 @@ int8_numeric(PG_FUNCTION_ARGS) ...@@ -1712,16 +1656,15 @@ int8_numeric(PG_FUNCTION_ARGS)
} }
int64 * Datum
numeric_int8(Numeric num) numeric_int8(PG_FUNCTION_ARGS)
{ {
Numeric num = PG_GETARG_NUMERIC(0);
NumericVar x; NumericVar x;
char *str; char *str;
Datum result; Datum result;
if (num == NULL) /* XXX would it be better to return NULL? */
return NULL;
if (NUMERIC_IS_NAN(num)) if (NUMERIC_IS_NAN(num))
elog(ERROR, "Cannot convert NaN to int8"); elog(ERROR, "Cannot convert NaN to int8");
...@@ -1737,10 +1680,9 @@ numeric_int8(Numeric num) ...@@ -1737,10 +1680,9 @@ numeric_int8(Numeric num)
free_var(&x); free_var(&x);
result = DirectFunctionCall1(int8in, CStringGetDatum(str)); result = DirectFunctionCall1(int8in, CStringGetDatum(str));
pfree(str); pfree(str);
return (int64 *) (result); PG_RETURN_DATUM(result);
} }
...@@ -1795,20 +1737,18 @@ numeric_int2(PG_FUNCTION_ARGS) ...@@ -1795,20 +1737,18 @@ numeric_int2(PG_FUNCTION_ARGS)
} }
Numeric Datum
float8_numeric(float64 val) float8_numeric(PG_FUNCTION_ARGS)
{ {
float8 val = PG_GETARG_FLOAT8(0);
Numeric res; Numeric res;
NumericVar result; NumericVar result;
char buf[DBL_DIG + 100]; char buf[DBL_DIG + 100];
if (val == NULL) if (isnan(val))
return NULL; PG_RETURN_NUMERIC(make_result(&const_nan));
if (isnan(*val))
return make_result(&const_nan);
sprintf(buf, "%.*g", DBL_DIG, *val); sprintf(buf, "%.*g", DBL_DIG, val);
init_var(&result); init_var(&result);
...@@ -1817,49 +1757,41 @@ float8_numeric(float64 val) ...@@ -1817,49 +1757,41 @@ float8_numeric(float64 val)
free_var(&result); free_var(&result);
return res; PG_RETURN_NUMERIC(res);
} }
float64 Datum
numeric_float8(Numeric num) numeric_float8(PG_FUNCTION_ARGS)
{ {
Numeric num = PG_GETARG_NUMERIC(0);
char *tmp; char *tmp;
float64 result; float64 result;
if (num == NULL)
return NULL;
if (NUMERIC_IS_NAN(num)) if (NUMERIC_IS_NAN(num))
{ PG_RETURN_FLOAT8(NAN);
result = (float64) palloc(sizeof(float64data));
*result = NAN;
return result;
}
tmp = DatumGetCString(DirectFunctionCall1(numeric_out, tmp = DatumGetCString(DirectFunctionCall1(numeric_out,
NumericGetDatum(num))); NumericGetDatum(num)));
result = float8in(tmp); result = float8in(tmp);
pfree(tmp); pfree(tmp);
return result; PG_RETURN_POINTER(result);
} }
Numeric Datum
float4_numeric(float32 val) float4_numeric(PG_FUNCTION_ARGS)
{ {
float4 val = PG_GETARG_FLOAT4(0);
Numeric res; Numeric res;
NumericVar result; NumericVar result;
char buf[FLT_DIG + 100]; char buf[FLT_DIG + 100];
if (val == NULL) if (isnan(val))
return NULL; PG_RETURN_NUMERIC(make_result(&const_nan));
if (isnan(*val))
return make_result(&const_nan);
sprintf(buf, "%.*g", FLT_DIG, *val); sprintf(buf, "%.*g", FLT_DIG, val);
init_var(&result); init_var(&result);
...@@ -1868,32 +1800,26 @@ float4_numeric(float32 val) ...@@ -1868,32 +1800,26 @@ float4_numeric(float32 val)
free_var(&result); free_var(&result);
return res; PG_RETURN_NUMERIC(res);
} }
float32 Datum
numeric_float4(Numeric num) numeric_float4(PG_FUNCTION_ARGS)
{ {
Numeric num = PG_GETARG_NUMERIC(0);
char *tmp; char *tmp;
float32 result; float32 result;
if (num == NULL)
return NULL;
if (NUMERIC_IS_NAN(num)) if (NUMERIC_IS_NAN(num))
{ PG_RETURN_FLOAT4(NAN);
result = (float32) palloc(sizeof(float32data));
*result = NAN;
return result;
}
tmp = DatumGetCString(DirectFunctionCall1(numeric_out, tmp = DatumGetCString(DirectFunctionCall1(numeric_out,
NumericGetDatum(num))); NumericGetDatum(num)));
result = float4in(tmp); result = float4in(tmp);
pfree(tmp); pfree(tmp);
return result; PG_RETURN_POINTER(result);
} }
...@@ -1915,7 +1841,7 @@ do_numeric_accum(ArrayType *transarray, Numeric newval) ...@@ -1915,7 +1841,7 @@ do_numeric_accum(ArrayType *transarray, Numeric newval)
{ {
Datum *transdatums; Datum *transdatums;
int ndatums; int ndatums;
Numeric N, Datum N,
sumX, sumX,
sumX2; sumX2;
ArrayType *result; ArrayType *result;
...@@ -1926,17 +1852,21 @@ do_numeric_accum(ArrayType *transarray, Numeric newval) ...@@ -1926,17 +1852,21 @@ do_numeric_accum(ArrayType *transarray, Numeric newval)
&transdatums, &ndatums); &transdatums, &ndatums);
if (ndatums != 3) if (ndatums != 3)
elog(ERROR, "do_numeric_accum: expected 3-element numeric array"); elog(ERROR, "do_numeric_accum: expected 3-element numeric array");
N = DatumGetNumeric(transdatums[0]); N = transdatums[0];
sumX = DatumGetNumeric(transdatums[1]); sumX = transdatums[1];
sumX2 = DatumGetNumeric(transdatums[2]); sumX2 = transdatums[2];
N = numeric_inc(N); N = DirectFunctionCall1(numeric_inc, N);
sumX = numeric_add(sumX, newval); sumX = DirectFunctionCall2(numeric_add, sumX,
sumX2 = numeric_add(sumX2, numeric_mul(newval, newval)); NumericGetDatum(newval));
sumX2 = DirectFunctionCall2(numeric_add, sumX2,
transdatums[0] = NumericGetDatum(N); DirectFunctionCall2(numeric_mul,
transdatums[1] = NumericGetDatum(sumX); NumericGetDatum(newval),
transdatums[2] = NumericGetDatum(sumX2); NumericGetDatum(newval)));
transdatums[0] = N;
transdatums[1] = sumX;
transdatums[2] = sumX2;
result = construct_array(transdatums, 3, result = construct_array(transdatums, 3,
false, -1, 'i'); false, -1, 'i');
...@@ -2018,7 +1948,9 @@ numeric_avg(PG_FUNCTION_ARGS) ...@@ -2018,7 +1948,9 @@ numeric_avg(PG_FUNCTION_ARGS)
if (N->varlen == NUMERIC_HDRSZ) if (N->varlen == NUMERIC_HDRSZ)
PG_RETURN_NULL(); PG_RETURN_NULL();
PG_RETURN_NUMERIC(numeric_div(sumX, N)); PG_RETURN_DATUM(DirectFunctionCall2(numeric_div,
NumericGetDatum(sumX),
NumericGetDatum(N)));
} }
Datum Datum
...@@ -2172,8 +2104,8 @@ numeric_stddev(PG_FUNCTION_ARGS) ...@@ -2172,8 +2104,8 @@ numeric_stddev(PG_FUNCTION_ARGS)
Datum Datum
int2_sum(PG_FUNCTION_ARGS) int2_sum(PG_FUNCTION_ARGS)
{ {
Numeric oldsum, Numeric oldsum;
newval; Datum newval;
if (PG_ARGISNULL(0)) if (PG_ARGISNULL(0))
{ {
...@@ -2181,9 +2113,8 @@ int2_sum(PG_FUNCTION_ARGS) ...@@ -2181,9 +2113,8 @@ int2_sum(PG_FUNCTION_ARGS)
if (PG_ARGISNULL(1)) if (PG_ARGISNULL(1))
PG_RETURN_NULL(); /* still no non-null */ PG_RETURN_NULL(); /* still no non-null */
/* This is the first non-null input. */ /* This is the first non-null input. */
newval = DatumGetNumeric(DirectFunctionCall1(int2_numeric, newval = DirectFunctionCall1(int2_numeric, PG_GETARG_DATUM(1));
PG_GETARG_DATUM(1))); PG_RETURN_DATUM(newval);
PG_RETURN_NUMERIC(newval);
} }
oldsum = PG_GETARG_NUMERIC(0); oldsum = PG_GETARG_NUMERIC(0);
...@@ -2193,17 +2124,17 @@ int2_sum(PG_FUNCTION_ARGS) ...@@ -2193,17 +2124,17 @@ int2_sum(PG_FUNCTION_ARGS)
PG_RETURN_NUMERIC(oldsum); PG_RETURN_NUMERIC(oldsum);
/* OK to do the addition. */ /* OK to do the addition. */
newval = DatumGetNumeric(DirectFunctionCall1(int2_numeric, newval = DirectFunctionCall1(int2_numeric, PG_GETARG_DATUM(1));
PG_GETARG_DATUM(1)));
PG_RETURN_NUMERIC(numeric_add(oldsum, newval)); PG_RETURN_DATUM(DirectFunctionCall2(numeric_add,
NumericGetDatum(oldsum), newval));
} }
Datum Datum
int4_sum(PG_FUNCTION_ARGS) int4_sum(PG_FUNCTION_ARGS)
{ {
Numeric oldsum, Numeric oldsum;
newval; Datum newval;
if (PG_ARGISNULL(0)) if (PG_ARGISNULL(0))
{ {
...@@ -2211,9 +2142,8 @@ int4_sum(PG_FUNCTION_ARGS) ...@@ -2211,9 +2142,8 @@ int4_sum(PG_FUNCTION_ARGS)
if (PG_ARGISNULL(1)) if (PG_ARGISNULL(1))
PG_RETURN_NULL(); /* still no non-null */ PG_RETURN_NULL(); /* still no non-null */
/* This is the first non-null input. */ /* This is the first non-null input. */
newval = DatumGetNumeric(DirectFunctionCall1(int4_numeric, newval = DirectFunctionCall1(int4_numeric, PG_GETARG_DATUM(1));
PG_GETARG_DATUM(1))); PG_RETURN_DATUM(newval);
PG_RETURN_NUMERIC(newval);
} }
oldsum = PG_GETARG_NUMERIC(0); oldsum = PG_GETARG_NUMERIC(0);
...@@ -2223,17 +2153,17 @@ int4_sum(PG_FUNCTION_ARGS) ...@@ -2223,17 +2153,17 @@ int4_sum(PG_FUNCTION_ARGS)
PG_RETURN_NUMERIC(oldsum); PG_RETURN_NUMERIC(oldsum);
/* OK to do the addition. */ /* OK to do the addition. */
newval = DatumGetNumeric(DirectFunctionCall1(int4_numeric, newval = DirectFunctionCall1(int4_numeric, PG_GETARG_DATUM(1));
PG_GETARG_DATUM(1)));
PG_RETURN_NUMERIC(numeric_add(oldsum, newval)); PG_RETURN_DATUM(DirectFunctionCall2(numeric_add,
NumericGetDatum(oldsum), newval));
} }
Datum Datum
int8_sum(PG_FUNCTION_ARGS) int8_sum(PG_FUNCTION_ARGS)
{ {
Numeric oldsum, Numeric oldsum;
newval; Datum newval;
if (PG_ARGISNULL(0)) if (PG_ARGISNULL(0))
{ {
...@@ -2241,9 +2171,8 @@ int8_sum(PG_FUNCTION_ARGS) ...@@ -2241,9 +2171,8 @@ int8_sum(PG_FUNCTION_ARGS)
if (PG_ARGISNULL(1)) if (PG_ARGISNULL(1))
PG_RETURN_NULL(); /* still no non-null */ PG_RETURN_NULL(); /* still no non-null */
/* This is the first non-null input. */ /* This is the first non-null input. */
newval = DatumGetNumeric(DirectFunctionCall1(int8_numeric, newval = DirectFunctionCall1(int8_numeric, PG_GETARG_DATUM(1));
PG_GETARG_DATUM(1))); PG_RETURN_DATUM(newval);
PG_RETURN_NUMERIC(newval);
} }
oldsum = PG_GETARG_NUMERIC(0); oldsum = PG_GETARG_NUMERIC(0);
...@@ -2253,10 +2182,10 @@ int8_sum(PG_FUNCTION_ARGS) ...@@ -2253,10 +2182,10 @@ int8_sum(PG_FUNCTION_ARGS)
PG_RETURN_NUMERIC(oldsum); PG_RETURN_NUMERIC(oldsum);
/* OK to do the addition. */ /* OK to do the addition. */
newval = DatumGetNumeric(DirectFunctionCall1(int8_numeric, newval = DirectFunctionCall1(int8_numeric, PG_GETARG_DATUM(1));
PG_GETARG_DATUM(1)));
PG_RETURN_NUMERIC(numeric_add(oldsum, newval)); PG_RETURN_DATUM(DirectFunctionCall2(numeric_add,
NumericGetDatum(oldsum), newval));
} }
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.75 2000/07/06 05:48:11 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.76 2000/07/29 03:26:42 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -818,7 +818,8 @@ convert_numeric_to_scalar(Datum value, Oid typid) ...@@ -818,7 +818,8 @@ convert_numeric_to_scalar(Datum value, Oid typid)
case FLOAT8OID: case FLOAT8OID:
return (double) DatumGetFloat8(value); return (double) DatumGetFloat8(value);
case NUMERICOID: case NUMERICOID:
return (double) (*numeric_float8((Numeric) DatumGetPointer(value))); return (double) DatumGetFloat8(DirectFunctionCall1(numeric_float8,
value));
case OIDOID: case OIDOID:
case REGPROCOID: case REGPROCOID:
/* we can treat OIDs as integers... */ /* we can treat OIDs as integers... */
...@@ -1825,11 +1826,13 @@ string_lessthan(const char *str1, const char *str2, Oid datatype) ...@@ -1825,11 +1826,13 @@ string_lessthan(const char *str1, const char *str2, Oid datatype)
break; break;
case BPCHAROID: case BPCHAROID:
result = bpcharlt((char *) datum1, (char *) datum2); result = DatumGetBool(DirectFunctionCall2(bpcharlt,
datum1, datum2));
break; break;
case VARCHAROID: case VARCHAROID:
result = varcharlt((char *) datum1, (char *) datum2); result = DatumGetBool(DirectFunctionCall2(varcharlt,
datum1, datum2));
break; break;
case NAMEOID: case NAMEOID:
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.68 2000/07/07 21:12:50 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.69 2000/07/29 03:26:42 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -260,19 +260,20 @@ char_bpchar(PG_FUNCTION_ARGS) ...@@ -260,19 +260,20 @@ char_bpchar(PG_FUNCTION_ARGS)
/* bpchar_name() /* bpchar_name()
* Converts a bpchar() type to a NameData type. * Converts a bpchar() type to a NameData type.
*/ */
NameData * Datum
bpchar_name(char *s) bpchar_name(PG_FUNCTION_ARGS)
{ {
NameData *result; BpChar *s = PG_GETARG_BPCHAR_P(0);
Name result;
int len; int len;
if (s == NULL)
return NULL;
len = VARSIZE(s) - VARHDRSZ; len = VARSIZE(s) - VARHDRSZ;
/* Truncate to max length for a Name */
if (len >= NAMEDATALEN) if (len >= NAMEDATALEN)
len = NAMEDATALEN-1; len = NAMEDATALEN-1;
/* Remove trailing blanks */
while (len > 0) while (len > 0)
{ {
if (*(VARDATA(s) + len - 1) != ' ') if (*(VARDATA(s) + len - 1) != ' ')
...@@ -280,49 +281,36 @@ bpchar_name(char *s) ...@@ -280,49 +281,36 @@ bpchar_name(char *s)
len--; len--;
} }
#ifdef STRINGDEBUG
printf("bpchar- convert string length %d (%d) ->%d\n",
VARSIZE(s) - VARHDRSZ, VARSIZE(s), len);
#endif
result = (NameData *) palloc(NAMEDATALEN); result = (NameData *) palloc(NAMEDATALEN);
memcpy(NameStr(*result), VARDATA(s), len); memcpy(NameStr(*result), VARDATA(s), len);
/* now null pad to full length... */ /* Now null pad to full length... */
while (len < NAMEDATALEN) while (len < NAMEDATALEN)
{ {
*(NameStr(*result) + len) = '\0'; *(NameStr(*result) + len) = '\0';
len++; len++;
} }
return result; PG_RETURN_NAME(result);
} /* bpchar_name() */ }
/* name_bpchar() /* name_bpchar()
* Converts a NameData type to a bpchar type. * Converts a NameData type to a bpchar type.
*/ */
char * Datum
name_bpchar(NameData *s) name_bpchar(PG_FUNCTION_ARGS)
{ {
char *result; Name s = PG_GETARG_NAME(0);
BpChar *result;
int len; int len;
if (s == NULL)
return NULL;
len = strlen(NameStr(*s)); len = strlen(NameStr(*s));
result = (BpChar *) palloc(VARHDRSZ + len);
#ifdef STRINGDEBUG
printf("bpchar- convert string length %d (%d) ->%d\n",
VARSIZE(s) - VARHDRSZ, VARSIZE(s), len);
#endif
result = (char *) palloc(VARHDRSZ + len);
memcpy(VARDATA(result), NameStr(*s), len); memcpy(VARDATA(result), NameStr(*s), len);
VARATT_SIZEP(result) = len + VARHDRSZ; VARATT_SIZEP(result) = len + VARHDRSZ;
return result; PG_RETURN_BPCHAR_P(result);
} /* name_bpchar() */ }
/***************************************************************************** /*****************************************************************************
...@@ -446,13 +434,9 @@ _varchar(PG_FUNCTION_ARGS) ...@@ -446,13 +434,9 @@ _varchar(PG_FUNCTION_ARGS)
return array_map(&locfcinfo, VARCHAROID, VARCHAROID); return array_map(&locfcinfo, VARCHAROID, VARCHAROID);
} }
/* "True" length (not counting trailing blanks) of a BpChar */
/*****************************************************************************
* Comparison Functions used for bpchar
*****************************************************************************/
static int static int
bcTruelen(char *arg) bcTruelen(BpChar *arg)
{ {
char *s = VARDATA(arg); char *s = VARDATA(arg);
int i; int i;
...@@ -467,19 +451,16 @@ bcTruelen(char *arg) ...@@ -467,19 +451,16 @@ bcTruelen(char *arg)
return i + 1; return i + 1;
} }
int32 Datum
bpcharlen(char *arg) bpcharlen(PG_FUNCTION_ARGS)
{ {
BpChar *arg = PG_GETARG_BPCHAR_P(0);
#ifdef MULTIBYTE #ifdef MULTIBYTE
unsigned char *s; unsigned char *s;
int len, int len,
l, l,
wl; wl;
#endif
if (!PointerIsValid(arg))
elog(ERROR, "Bad (null) char() external representation");
#ifdef MULTIBYTE
l = VARSIZE(arg) - VARHDRSZ; l = VARSIZE(arg) - VARHDRSZ;
len = 0; len = 0;
s = VARDATA(arg); s = VARDATA(arg);
...@@ -490,134 +471,160 @@ bpcharlen(char *arg) ...@@ -490,134 +471,160 @@ bpcharlen(char *arg)
s += wl; s += wl;
len++; len++;
} }
return (len); PG_RETURN_INT32(len);
#else #else
return (VARSIZE(arg) - VARHDRSZ); PG_RETURN_INT32(VARSIZE(arg) - VARHDRSZ);
#endif #endif
} }
int32 Datum
bpcharoctetlen(char *arg) bpcharoctetlen(PG_FUNCTION_ARGS)
{ {
if (!PointerIsValid(arg)) BpChar *arg = PG_GETARG_BPCHAR_P(0);
elog(ERROR, "Bad (null) char() external representation");
return (VARSIZE(arg) - VARHDRSZ); PG_RETURN_INT32(VARSIZE(arg) - VARHDRSZ);
} }
bool
bpchareq(char *arg1, char *arg2) /*****************************************************************************
* Comparison Functions used for bpchar
*
* Note: btree indexes need these routines not to leak memory; therefore,
* be careful to free working copies of toasted datums. Most places don't
* need to be so careful.
*****************************************************************************/
Datum
bpchareq(PG_FUNCTION_ARGS)
{ {
BpChar *arg1 = PG_GETARG_BPCHAR_P(0);
BpChar *arg2 = PG_GETARG_BPCHAR_P(1);
int len1, int len1,
len2; len2;
bool result;
if (arg1 == NULL || arg2 == NULL)
return (bool) 0;
len1 = bcTruelen(arg1); len1 = bcTruelen(arg1);
len2 = bcTruelen(arg2); len2 = bcTruelen(arg2);
if (len1 != len2) if (len1 != len2)
return 0; result = false;
else
result = (strncmp(VARDATA(arg1), VARDATA(arg2), len1) == 0);
return strncmp(VARDATA(arg1), VARDATA(arg2), len1) == 0; PG_FREE_IF_COPY(arg1, 0);
PG_FREE_IF_COPY(arg2, 1);
PG_RETURN_BOOL(result);
} }
bool Datum
bpcharne(char *arg1, char *arg2) bpcharne(PG_FUNCTION_ARGS)
{ {
BpChar *arg1 = PG_GETARG_BPCHAR_P(0);
BpChar *arg2 = PG_GETARG_BPCHAR_P(1);
int len1, int len1,
len2; len2;
bool result;
if (arg1 == NULL || arg2 == NULL)
return (bool) 0;
len1 = bcTruelen(arg1); len1 = bcTruelen(arg1);
len2 = bcTruelen(arg2); len2 = bcTruelen(arg2);
if (len1 != len2) if (len1 != len2)
return 1; result = true;
else
result = (strncmp(VARDATA(arg1), VARDATA(arg2), len1) != 0);
PG_FREE_IF_COPY(arg1, 0);
PG_FREE_IF_COPY(arg2, 1);
return strncmp(VARDATA(arg1), VARDATA(arg2), len1) != 0; PG_RETURN_BOOL(result);
} }
bool Datum
bpcharlt(char *arg1, char *arg2) bpcharlt(PG_FUNCTION_ARGS)
{ {
BpChar *arg1 = PG_GETARG_BPCHAR_P(0);
BpChar *arg2 = PG_GETARG_BPCHAR_P(1);
int len1, int len1,
len2; len2;
int cmp; int cmp;
if (arg1 == NULL || arg2 == NULL)
return (bool) 0;
len1 = bcTruelen(arg1); len1 = bcTruelen(arg1);
len2 = bcTruelen(arg2); len2 = bcTruelen(arg2);
cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2);
if (cmp == 0)
return len1 < len2; PG_FREE_IF_COPY(arg1, 0);
else PG_FREE_IF_COPY(arg2, 1);
return cmp < 0;
PG_RETURN_BOOL(cmp < 0);
} }
bool Datum
bpcharle(char *arg1, char *arg2) bpcharle(PG_FUNCTION_ARGS)
{ {
BpChar *arg1 = PG_GETARG_BPCHAR_P(0);
BpChar *arg2 = PG_GETARG_BPCHAR_P(1);
int len1, int len1,
len2; len2;
int cmp; int cmp;
if (arg1 == NULL || arg2 == NULL)
return (bool) 0;
len1 = bcTruelen(arg1); len1 = bcTruelen(arg1);
len2 = bcTruelen(arg2); len2 = bcTruelen(arg2);
cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2);
if (0 == cmp)
return (bool) (len1 <= len2 ? 1 : 0); PG_FREE_IF_COPY(arg1, 0);
else PG_FREE_IF_COPY(arg2, 1);
return (bool) (cmp <= 0);
PG_RETURN_BOOL(cmp <= 0);
} }
bool Datum
bpchargt(char *arg1, char *arg2) bpchargt(PG_FUNCTION_ARGS)
{ {
BpChar *arg1 = PG_GETARG_BPCHAR_P(0);
BpChar *arg2 = PG_GETARG_BPCHAR_P(1);
int len1, int len1,
len2; len2;
int cmp; int cmp;
if (arg1 == NULL || arg2 == NULL)
return (bool) 0;
len1 = bcTruelen(arg1); len1 = bcTruelen(arg1);
len2 = bcTruelen(arg2); len2 = bcTruelen(arg2);
cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2);
if (cmp == 0)
return len1 > len2; PG_FREE_IF_COPY(arg1, 0);
else PG_FREE_IF_COPY(arg2, 1);
return cmp > 0;
PG_RETURN_BOOL(cmp > 0);
} }
bool Datum
bpcharge(char *arg1, char *arg2) bpcharge(PG_FUNCTION_ARGS)
{ {
BpChar *arg1 = PG_GETARG_BPCHAR_P(0);
BpChar *arg2 = PG_GETARG_BPCHAR_P(1);
int len1, int len1,
len2; len2;
int cmp; int cmp;
if (arg1 == NULL || arg2 == NULL)
return (bool) 0;
len1 = bcTruelen(arg1); len1 = bcTruelen(arg1);
len2 = bcTruelen(arg2); len2 = bcTruelen(arg2);
cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2);
if (0 == cmp)
return (bool) (len1 >= len2 ? 1 : 0); PG_FREE_IF_COPY(arg1, 0);
else PG_FREE_IF_COPY(arg2, 1);
return (bool) (cmp >= 0);
PG_RETURN_BOOL(cmp >= 0);
} }
int32 Datum
bpcharcmp(char *arg1, char *arg2) bpcharcmp(PG_FUNCTION_ARGS)
{ {
BpChar *arg1 = PG_GETARG_BPCHAR_P(0);
BpChar *arg2 = PG_GETARG_BPCHAR_P(1);
int len1, int len1,
len2; len2;
int cmp; int cmp;
...@@ -626,30 +633,46 @@ bpcharcmp(char *arg1, char *arg2) ...@@ -626,30 +633,46 @@ bpcharcmp(char *arg1, char *arg2)
len2 = bcTruelen(arg2); len2 = bcTruelen(arg2);
cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2);
if ((0 == cmp) && (len1 != len2))
return (int32) (len1 < len2 ? -1 : 1); PG_FREE_IF_COPY(arg1, 0);
else PG_FREE_IF_COPY(arg2, 1);
return cmp;
PG_RETURN_INT32(cmp);
} }
/*
* bpchar needs a specialized hash function because we want to ignore
* trailing blanks in comparisons. (varchar can use plain hashvarlena.)
*/
Datum
hashbpchar(PG_FUNCTION_ARGS)
{
BpChar *key = PG_GETARG_BPCHAR_P(0);
char *keydata;
int keylen;
keydata = VARDATA(key);
keylen = bcTruelen(key);
return hash_any(keydata, keylen);
}
/***************************************************************************** /*****************************************************************************
* Comparison Functions used for varchar * Functions used for varchar
*****************************************************************************/ *****************************************************************************/
int32 Datum
varcharlen(char *arg) varcharlen(PG_FUNCTION_ARGS)
{ {
VarChar *arg = PG_GETARG_VARCHAR_P(0);
#ifdef MULTIBYTE #ifdef MULTIBYTE
unsigned char *s; unsigned char *s;
int len, int len,
l, l,
wl; wl;
#endif
if (!PointerIsValid(arg))
elog(ERROR, "Bad (null) varchar() external representation");
#ifdef MULTIBYTE
len = 0; len = 0;
s = VARDATA(arg); s = VARDATA(arg);
l = VARSIZE(arg) - VARHDRSZ; l = VARSIZE(arg) - VARHDRSZ;
...@@ -660,161 +683,171 @@ varcharlen(char *arg) ...@@ -660,161 +683,171 @@ varcharlen(char *arg)
s += wl; s += wl;
len++; len++;
} }
return (len); PG_RETURN_INT32(len);
#else #else
return VARSIZE(arg) - VARHDRSZ; PG_RETURN_INT32(VARSIZE(arg) - VARHDRSZ);
#endif #endif
} }
int32 Datum
varcharoctetlen(char *arg) varcharoctetlen(PG_FUNCTION_ARGS)
{ {
if (!PointerIsValid(arg)) VarChar *arg = PG_GETARG_VARCHAR_P(0);
elog(ERROR, "Bad (null) varchar() external representation");
return VARSIZE(arg) - VARHDRSZ; PG_RETURN_INT32(VARSIZE(arg) - VARHDRSZ);
} }
bool
varchareq(char *arg1, char *arg2) /*****************************************************************************
* Comparison Functions used for varchar
*
* Note: btree indexes need these routines not to leak memory; therefore,
* be careful to free working copies of toasted datums. Most places don't
* need to be so careful.
*****************************************************************************/
Datum
varchareq(PG_FUNCTION_ARGS)
{ {
VarChar *arg1 = PG_GETARG_VARCHAR_P(0);
VarChar *arg2 = PG_GETARG_VARCHAR_P(1);
int len1, int len1,
len2; len2;
bool result;
if (arg1 == NULL || arg2 == NULL)
return (bool) 0;
len1 = VARSIZE(arg1) - VARHDRSZ; len1 = VARSIZE(arg1) - VARHDRSZ;
len2 = VARSIZE(arg2) - VARHDRSZ; len2 = VARSIZE(arg2) - VARHDRSZ;
if (len1 != len2) if (len1 != len2)
return 0; result = false;
else
result = (strncmp(VARDATA(arg1), VARDATA(arg2), len1) == 0);
return strncmp(VARDATA(arg1), VARDATA(arg2), len1) == 0; PG_FREE_IF_COPY(arg1, 0);
PG_FREE_IF_COPY(arg2, 1);
PG_RETURN_BOOL(result);
} }
bool Datum
varcharne(char *arg1, char *arg2) varcharne(PG_FUNCTION_ARGS)
{ {
VarChar *arg1 = PG_GETARG_VARCHAR_P(0);
VarChar *arg2 = PG_GETARG_VARCHAR_P(1);
int len1, int len1,
len2; len2;
bool result;
if (arg1 == NULL || arg2 == NULL)
return (bool) 0;
len1 = VARSIZE(arg1) - VARHDRSZ; len1 = VARSIZE(arg1) - VARHDRSZ;
len2 = VARSIZE(arg2) - VARHDRSZ; len2 = VARSIZE(arg2) - VARHDRSZ;
if (len1 != len2) if (len1 != len2)
return 1; result = true;
else
result = (strncmp(VARDATA(arg1), VARDATA(arg2), len1) != 0);
PG_FREE_IF_COPY(arg1, 0);
PG_FREE_IF_COPY(arg2, 1);
return strncmp(VARDATA(arg1), VARDATA(arg2), len1) != 0; PG_RETURN_BOOL(result);
} }
bool Datum
varcharlt(char *arg1, char *arg2) varcharlt(PG_FUNCTION_ARGS)
{ {
VarChar *arg1 = PG_GETARG_VARCHAR_P(0);
VarChar *arg2 = PG_GETARG_VARCHAR_P(1);
int len1, int len1,
len2; len2;
int cmp; int cmp;
if (arg1 == NULL || arg2 == NULL)
return (bool) 0;
len1 = VARSIZE(arg1) - VARHDRSZ; len1 = VARSIZE(arg1) - VARHDRSZ;
len2 = VARSIZE(arg2) - VARHDRSZ; len2 = VARSIZE(arg2) - VARHDRSZ;
cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2);
if (cmp == 0)
return len1 < len2; PG_FREE_IF_COPY(arg1, 0);
else PG_FREE_IF_COPY(arg2, 1);
return cmp < 0;
PG_RETURN_BOOL(cmp < 0);
} }
bool Datum
varcharle(char *arg1, char *arg2) varcharle(PG_FUNCTION_ARGS)
{ {
VarChar *arg1 = PG_GETARG_VARCHAR_P(0);
VarChar *arg2 = PG_GETARG_VARCHAR_P(1);
int len1, int len1,
len2; len2;
int cmp; int cmp;
if (arg1 == NULL || arg2 == NULL)
return (bool) 0;
len1 = VARSIZE(arg1) - VARHDRSZ; len1 = VARSIZE(arg1) - VARHDRSZ;
len2 = VARSIZE(arg2) - VARHDRSZ; len2 = VARSIZE(arg2) - VARHDRSZ;
cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2);
if (0 == cmp)
return (bool) (len1 <= len2 ? 1 : 0); PG_FREE_IF_COPY(arg1, 0);
else PG_FREE_IF_COPY(arg2, 1);
return (bool) (cmp <= 0);
PG_RETURN_BOOL(cmp <= 0);
} }
bool Datum
varchargt(char *arg1, char *arg2) varchargt(PG_FUNCTION_ARGS)
{ {
VarChar *arg1 = PG_GETARG_VARCHAR_P(0);
VarChar *arg2 = PG_GETARG_VARCHAR_P(1);
int len1, int len1,
len2; len2;
int cmp; int cmp;
if (arg1 == NULL || arg2 == NULL)
return (bool) 0;
len1 = VARSIZE(arg1) - VARHDRSZ; len1 = VARSIZE(arg1) - VARHDRSZ;
len2 = VARSIZE(arg2) - VARHDRSZ; len2 = VARSIZE(arg2) - VARHDRSZ;
cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2);
if (cmp == 0)
return len1 > len2; PG_FREE_IF_COPY(arg1, 0);
else PG_FREE_IF_COPY(arg2, 1);
return cmp > 0;
PG_RETURN_BOOL(cmp > 0);
} }
bool Datum
varcharge(char *arg1, char *arg2) varcharge(PG_FUNCTION_ARGS)
{ {
VarChar *arg1 = PG_GETARG_VARCHAR_P(0);
VarChar *arg2 = PG_GETARG_VARCHAR_P(1);
int len1, int len1,
len2; len2;
int cmp; int cmp;
if (arg1 == NULL || arg2 == NULL)
return (bool) 0;
len1 = VARSIZE(arg1) - VARHDRSZ; len1 = VARSIZE(arg1) - VARHDRSZ;
len2 = VARSIZE(arg2) - VARHDRSZ; len2 = VARSIZE(arg2) - VARHDRSZ;
cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2);
if (0 == cmp)
return (bool) (len1 >= len2 ? 1 : 0);
else
return (bool) (cmp >= 0);
PG_FREE_IF_COPY(arg1, 0);
PG_FREE_IF_COPY(arg2, 1);
PG_RETURN_BOOL(cmp >= 0);
} }
int32 Datum
varcharcmp(char *arg1, char *arg2) varcharcmp(PG_FUNCTION_ARGS)
{ {
VarChar *arg1 = PG_GETARG_VARCHAR_P(0);
VarChar *arg2 = PG_GETARG_VARCHAR_P(1);
int len1, int len1,
len2; len2;
int cmp; int cmp;
len1 = VARSIZE(arg1) - VARHDRSZ; len1 = VARSIZE(arg1) - VARHDRSZ;
len2 = VARSIZE(arg2) - VARHDRSZ; len2 = VARSIZE(arg2) - VARHDRSZ;
cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2);
if ((0 == cmp) && (len1 != len2))
return (int32) (len1 < len2 ? -1 : 1);
else
return (int32) (cmp);
}
/* cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2);
* bpchar needs a specialized hash function because we want to ignore
* trailing blanks in comparisons. (varchar can use plain hashvarlena.)
*/
Datum
hashbpchar(PG_FUNCTION_ARGS)
{
BpChar *key = PG_GETARG_BPCHAR_P(0);
char *keydata;
int keylen;
keydata = VARDATA(key); PG_FREE_IF_COPY(arg1, 0);
keylen = bcTruelen((char *) key); PG_FREE_IF_COPY(arg2, 1);
return hash_any(keydata, keylen); PG_RETURN_INT32(cmp);
} }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.64 2000/07/12 02:37:19 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.65 2000/07/29 03:26:42 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -41,18 +41,17 @@ static int text_cmp(text *arg1, text *arg2); ...@@ -41,18 +41,17 @@ static int text_cmp(text *arg1, text *arg2);
* The input is scaned twice. * The input is scaned twice.
* The error checking of input is minimal. * The error checking of input is minimal.
*/ */
bytea * Datum
byteain(char *inputText) byteain(PG_FUNCTION_ARGS)
{ {
char *inputText = PG_GETARG_CSTRING(0);
char *tp; char *tp;
char *rp; char *rp;
int byte; int byte;
bytea *result; bytea *result;
if (inputText == NULL)
elog(ERROR, "Bad input string for type bytea");
for (byte = 0, tp = inputText; *tp != '\0'; byte++) for (byte = 0, tp = inputText; *tp != '\0'; byte++)
{
if (*tp++ == '\\') if (*tp++ == '\\')
{ {
if (*tp == '\\') if (*tp == '\\')
...@@ -62,12 +61,16 @@ byteain(char *inputText) ...@@ -62,12 +61,16 @@ byteain(char *inputText)
!isdigit((int) *tp++)) !isdigit((int) *tp++))
elog(ERROR, "Bad input string for type bytea"); elog(ERROR, "Bad input string for type bytea");
} }
tp = inputText; }
byte += VARHDRSZ; byte += VARHDRSZ;
result = (bytea *) palloc(byte); result = (bytea *) palloc(byte);
result->vl_len = byte; /* varlena? */ result->vl_len = byte; /* set varlena length */
tp = inputText;
rp = result->vl_dat; rp = result->vl_dat;
while (*tp != '\0') while (*tp != '\0')
{
if (*tp != '\\' || *++tp == '\\') if (*tp != '\\' || *++tp == '\\')
*rp++ = *tp++; *rp++ = *tp++;
else else
...@@ -78,7 +81,9 @@ byteain(char *inputText) ...@@ -78,7 +81,9 @@ byteain(char *inputText)
byte <<= 3; byte <<= 3;
*rp++ = byte + VAL(*tp++); *rp++ = byte + VAL(*tp++);
} }
return result; }
PG_RETURN_BYTEA_P(result);
} }
/* /*
...@@ -89,9 +94,10 @@ byteain(char *inputText) ...@@ -89,9 +94,10 @@ byteain(char *inputText)
* *
* NULL vlena should be an error--returning string with NULL for now. * NULL vlena should be an error--returning string with NULL for now.
*/ */
char * Datum
byteaout(bytea *vlena) byteaout(PG_FUNCTION_ARGS)
{ {
bytea *vlena = PG_GETARG_BYTEA_P(0);
char *result; char *result;
char *vp; char *vp;
char *rp; char *rp;
...@@ -99,47 +105,42 @@ byteaout(bytea *vlena) ...@@ -99,47 +105,42 @@ byteaout(bytea *vlena)
int i; int i;
int len; int len;
if (vlena == NULL)
{
result = (char *) palloc(2);
result[0] = '-';
result[1] = '\0';
return result;
}
vp = vlena->vl_dat;
len = 1; /* empty string has 1 char */ len = 1; /* empty string has 1 char */
vp = vlena->vl_dat;
for (i = vlena->vl_len - VARHDRSZ; i != 0; i--, vp++) for (i = vlena->vl_len - VARHDRSZ; i != 0; i--, vp++)
{
if (*vp == '\\') if (*vp == '\\')
len += 2; len += 2;
else if (isascii((int) *vp) && isprint((int) *vp)) else if (isascii((int) *vp) && isprint((int) *vp))
len++; len++;
else else
len += VARHDRSZ; len += 4;
}
rp = result = (char *) palloc(len); rp = result = (char *) palloc(len);
vp = vlena->vl_dat; vp = vlena->vl_dat;
for (i = vlena->vl_len - VARHDRSZ; i != 0; i--) for (i = vlena->vl_len - VARHDRSZ; i != 0; i--, vp++)
{
if (*vp == '\\') if (*vp == '\\')
{ {
vp++;
*rp++ = '\\'; *rp++ = '\\';
*rp++ = '\\'; *rp++ = '\\';
} }
else if (isascii((int) *vp) && isprint((int) *vp)) else if (isascii((int) *vp) && isprint((int) *vp))
*rp++ = *vp++; *rp++ = *vp;
else else
{ {
val = *vp++; val = *vp;
*rp = '\\'; rp[0] = '\\';
rp += 3; rp[3] = DIG(val & 07);
*rp-- = DIG(val & 07);
val >>= 3; val >>= 3;
*rp-- = DIG(val & 07); rp[2] = DIG(val & 07);
val >>= 3; val >>= 3;
*rp = DIG(val & 03); rp[1] = DIG(val & 03);
rp += 3; rp += 4;
} }
}
*rp = '\0'; *rp = '\0';
return result; PG_RETURN_CSTRING(result);
} }
...@@ -663,13 +664,12 @@ text_smaller(PG_FUNCTION_ARGS) ...@@ -663,13 +664,12 @@ text_smaller(PG_FUNCTION_ARGS)
* get the number of bytes contained in an instance of type 'bytea' * get the number of bytes contained in an instance of type 'bytea'
*------------------------------------------------------------- *-------------------------------------------------------------
*/ */
int32 Datum
byteaoctetlen(bytea *v) byteaoctetlen(PG_FUNCTION_ARGS)
{ {
if (!PointerIsValid(v)) bytea *v = PG_GETARG_BYTEA_P(0);
return 0;
return VARSIZE(v) - VARHDRSZ; PG_RETURN_INT32(VARSIZE(v) - VARHDRSZ);
} }
/*------------------------------------------------------------- /*-------------------------------------------------------------
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: pg_proc.h,v 1.149 2000/07/28 05:07:42 tgl Exp $ * $Id: pg_proc.h,v 1.150 2000/07/29 03:26:43 tgl Exp $
* *
* NOTES * NOTES
* The script catalog/genbki.sh reads this file and generates .bki * The script catalog/genbki.sh reads this file and generates .bki
...@@ -101,9 +101,9 @@ DATA(insert OID = 1242 ( boolin PGUID 12 f t t t 1 f 16 "0" 100 0 0 100 b ...@@ -101,9 +101,9 @@ DATA(insert OID = 1242 ( boolin PGUID 12 f t t t 1 f 16 "0" 100 0 0 100 b
DESCR("(internal)"); DESCR("(internal)");
DATA(insert OID = 1243 ( boolout PGUID 12 f t t t 1 f 23 "0" 100 0 0 100 boolout - )); DATA(insert OID = 1243 ( boolout PGUID 12 f t t t 1 f 23 "0" 100 0 0 100 boolout - ));
DESCR("(internal)"); DESCR("(internal)");
DATA(insert OID = 1244 ( byteain PGUID 11 f t t t 1 f 17 "0" 100 0 0 100 byteain - )); DATA(insert OID = 1244 ( byteain PGUID 12 f t t t 1 f 17 "0" 100 0 0 100 byteain - ));
DESCR("(internal)"); DESCR("(internal)");
DATA(insert OID = 31 ( byteaout PGUID 11 f t t t 1 f 23 "0" 100 0 0 100 byteaout - )); DATA(insert OID = 31 ( byteaout PGUID 12 f t t t 1 f 23 "0" 100 0 0 100 byteaout - ));
DESCR("(internal)"); DESCR("(internal)");
DATA(insert OID = 1245 ( charin PGUID 12 f t t t 1 f 18 "0" 100 0 0 100 charin - )); DATA(insert OID = 1245 ( charin PGUID 12 f t t t 1 f 18 "0" 100 0 0 100 charin - ));
DESCR("(internal)"); DESCR("(internal)");
...@@ -786,9 +786,9 @@ DATA(insert OID = 406 ( text PGUID 12 f t t t 1 f 25 "19" 100 0 0 100 nam ...@@ -786,9 +786,9 @@ DATA(insert OID = 406 ( text PGUID 12 f t t t 1 f 25 "19" 100 0 0 100 nam
DESCR("convert name to text"); DESCR("convert name to text");
DATA(insert OID = 407 ( name PGUID 12 f t t t 1 f 19 "25" 100 0 0 100 text_name - )); DATA(insert OID = 407 ( name PGUID 12 f t t t 1 f 19 "25" 100 0 0 100 text_name - ));
DESCR("convert text to name"); DESCR("convert text to name");
DATA(insert OID = 408 ( bpchar PGUID 11 f t t t 1 f 1042 "19" 100 0 0 100 name_bpchar - )); DATA(insert OID = 408 ( bpchar PGUID 12 f t t t 1 f 1042 "19" 100 0 0 100 name_bpchar - ));
DESCR("convert name to char()"); DESCR("convert name to char()");
DATA(insert OID = 409 ( name PGUID 11 f t t t 1 f 19 "1042" 100 0 0 100 bpchar_name - )); DATA(insert OID = 409 ( name PGUID 12 f t t t 1 f 19 "1042" 100 0 0 100 bpchar_name - ));
DESCR("convert char() to name"); DESCR("convert char() to name");
DATA(insert OID = 438 ( hashcostestimate PGUID 12 f t f t 7 f 0 "0 0 0 0 0 0 0" 100 0 0 100 hashcostestimate - )); DATA(insert OID = 438 ( hashcostestimate PGUID 12 f t f t 7 f 0 "0 0 0 0 0 0 0" 100 0 0 100 hashcostestimate - ));
...@@ -943,7 +943,7 @@ DESCR("equal"); ...@@ -943,7 +943,7 @@ DESCR("equal");
DATA(insert OID = 717 ( int4eqoid PGUID 12 f t t t 2 f 16 "23 26" 100 0 0 100 int4eqoid - )); DATA(insert OID = 717 ( int4eqoid PGUID 12 f t t t 2 f 16 "23 26" 100 0 0 100 int4eqoid - ));
DESCR("equal"); DESCR("equal");
DATA(insert OID = 720 ( octet_length PGUID 11 f t t t 1 f 23 "17" 100 0 0 100 byteaoctetlen - )); DATA(insert OID = 720 ( octet_length PGUID 12 f t t t 1 f 23 "17" 100 0 0 100 byteaoctetlen - ));
DESCR(""); DESCR("");
DATA(insert OID = 721 ( get_byte PGUID 12 f t t t 2 f 23 "17 23" 100 0 0 100 byteaGetByte - )); DATA(insert OID = 721 ( get_byte PGUID 12 f t t t 2 f 23 "17 23" 100 0 0 100 byteaGetByte - ));
DESCR(""); DESCR("");
...@@ -1293,33 +1293,33 @@ DATA(insert OID = 1046 ( varcharin PGUID 12 f t t t 3 f 1043 "0 26 23" 100 ...@@ -1293,33 +1293,33 @@ DATA(insert OID = 1046 ( varcharin PGUID 12 f t t t 3 f 1043 "0 26 23" 100
DESCR("(internal)"); DESCR("(internal)");
DATA(insert OID = 1047 ( varcharout PGUID 12 f t t t 1 f 23 "0" 100 0 0 100 varcharout - )); DATA(insert OID = 1047 ( varcharout PGUID 12 f t t t 1 f 23 "0" 100 0 0 100 varcharout - ));
DESCR("(internal)"); DESCR("(internal)");
DATA(insert OID = 1048 ( bpchareq PGUID 11 f t t t 2 f 16 "1042 1042" 100 0 0 100 bpchareq - )); DATA(insert OID = 1048 ( bpchareq PGUID 12 f t t t 2 f 16 "1042 1042" 100 0 0 100 bpchareq - ));
DESCR("equal"); DESCR("equal");
DATA(insert OID = 1049 ( bpcharlt PGUID 11 f t t t 2 f 16 "1042 1042" 100 0 0 100 bpcharlt - )); DATA(insert OID = 1049 ( bpcharlt PGUID 12 f t t t 2 f 16 "1042 1042" 100 0 0 100 bpcharlt - ));
DESCR("less-than"); DESCR("less-than");
DATA(insert OID = 1050 ( bpcharle PGUID 11 f t t t 2 f 16 "1042 1042" 100 0 0 100 bpcharle - )); DATA(insert OID = 1050 ( bpcharle PGUID 12 f t t t 2 f 16 "1042 1042" 100 0 0 100 bpcharle - ));
DESCR("less-than-or-equal"); DESCR("less-than-or-equal");
DATA(insert OID = 1051 ( bpchargt PGUID 11 f t t t 2 f 16 "1042 1042" 100 0 0 100 bpchargt - )); DATA(insert OID = 1051 ( bpchargt PGUID 12 f t t t 2 f 16 "1042 1042" 100 0 0 100 bpchargt - ));
DESCR("greater-than"); DESCR("greater-than");
DATA(insert OID = 1052 ( bpcharge PGUID 11 f t t t 2 f 16 "1042 1042" 100 0 0 100 bpcharge - )); DATA(insert OID = 1052 ( bpcharge PGUID 12 f t t t 2 f 16 "1042 1042" 100 0 0 100 bpcharge - ));
DESCR("greater-than-or-equal"); DESCR("greater-than-or-equal");
DATA(insert OID = 1053 ( bpcharne PGUID 11 f t t t 2 f 16 "1042 1042" 100 0 0 100 bpcharne - )); DATA(insert OID = 1053 ( bpcharne PGUID 12 f t t t 2 f 16 "1042 1042" 100 0 0 100 bpcharne - ));
DESCR("not equal"); DESCR("not equal");
DATA(insert OID = 1070 ( varchareq PGUID 11 f t t t 2 f 16 "1043 1043" 100 0 0 100 varchareq - )); DATA(insert OID = 1070 ( varchareq PGUID 12 f t t t 2 f 16 "1043 1043" 100 0 0 100 varchareq - ));
DESCR("equal"); DESCR("equal");
DATA(insert OID = 1071 ( varcharlt PGUID 11 f t t t 2 f 16 "1043 1043" 100 0 0 100 varcharlt - )); DATA(insert OID = 1071 ( varcharlt PGUID 12 f t t t 2 f 16 "1043 1043" 100 0 0 100 varcharlt - ));
DESCR("less-than"); DESCR("less-than");
DATA(insert OID = 1072 ( varcharle PGUID 11 f t t t 2 f 16 "1043 1043" 100 0 0 100 varcharle - )); DATA(insert OID = 1072 ( varcharle PGUID 12 f t t t 2 f 16 "1043 1043" 100 0 0 100 varcharle - ));
DESCR("less-than-or-equal"); DESCR("less-than-or-equal");
DATA(insert OID = 1073 ( varchargt PGUID 11 f t t t 2 f 16 "1043 1043" 100 0 0 100 varchargt - )); DATA(insert OID = 1073 ( varchargt PGUID 12 f t t t 2 f 16 "1043 1043" 100 0 0 100 varchargt - ));
DESCR("greater-than"); DESCR("greater-than");
DATA(insert OID = 1074 ( varcharge PGUID 11 f t t t 2 f 16 "1043 1043" 100 0 0 100 varcharge - )); DATA(insert OID = 1074 ( varcharge PGUID 12 f t t t 2 f 16 "1043 1043" 100 0 0 100 varcharge - ));
DESCR("greater-than-or-equal"); DESCR("greater-than-or-equal");
DATA(insert OID = 1075 ( varcharne PGUID 11 f t t t 2 f 16 "1043 1043" 100 0 0 100 varcharne - )); DATA(insert OID = 1075 ( varcharne PGUID 12 f t t t 2 f 16 "1043 1043" 100 0 0 100 varcharne - ));
DESCR("not equal"); DESCR("not equal");
DATA(insert OID = 1078 ( bpcharcmp PGUID 11 f t t t 2 f 23 "1042 1042" 100 0 0 100 bpcharcmp - )); DATA(insert OID = 1078 ( bpcharcmp PGUID 12 f t t t 2 f 23 "1042 1042" 100 0 0 100 bpcharcmp - ));
DESCR("less-equal-greater"); DESCR("less-equal-greater");
DATA(insert OID = 1079 ( varcharcmp PGUID 11 f t t t 2 f 23 "1043 1043" 100 0 0 100 varcharcmp - )); DATA(insert OID = 1079 ( varcharcmp PGUID 12 f t t t 2 f 23 "1043 1043" 100 0 0 100 varcharcmp - ));
DESCR("less-equal-greater"); DESCR("less-equal-greater");
DATA(insert OID = 1080 ( hashbpchar PGUID 12 f t t t 1 f 23 "1042" 100 0 0 100 hashbpchar - )); DATA(insert OID = 1080 ( hashbpchar PGUID 12 f t t t 1 f 23 "1042" 100 0 0 100 hashbpchar - ));
DESCR("hash"); DESCR("hash");
...@@ -1591,9 +1591,9 @@ DESCR("convert timestamp to time"); ...@@ -1591,9 +1591,9 @@ DESCR("convert timestamp to time");
DATA(insert OID = 1317 ( length PGUID 12 f t t t 1 f 23 "25" 100 0 1 0 textlen - )); DATA(insert OID = 1317 ( length PGUID 12 f t t t 1 f 23 "25" 100 0 1 0 textlen - ));
DESCR("length"); DESCR("length");
DATA(insert OID = 1318 ( length PGUID 11 f t t t 1 f 23 "1042" 100 0 0 100 bpcharlen - )); DATA(insert OID = 1318 ( length PGUID 12 f t t t 1 f 23 "1042" 100 0 0 100 bpcharlen - ));
DESCR("character length"); DESCR("character length");
DATA(insert OID = 1319 ( length PGUID 11 f t t t 1 f 23 "1043" 100 0 0 100 varcharlen - )); DATA(insert OID = 1319 ( length PGUID 12 f t t t 1 f 23 "1043" 100 0 0 100 varcharlen - ));
DESCR("character length"); DESCR("character length");
DATA(insert OID = 1326 ( interval_div PGUID 12 f t f t 2 f 1186 "1186 701" 100 0 0 100 interval_div - )); DATA(insert OID = 1326 ( interval_div PGUID 12 f t f t 2 f 1186 "1186 701" 100 0 0 100 interval_div - ));
...@@ -1661,16 +1661,16 @@ DATA(insert OID = 1370 ( interval PGUID 12 f t f t 1 f 1186 "1083" 100 0 0 1 ...@@ -1661,16 +1661,16 @@ DATA(insert OID = 1370 ( interval PGUID 12 f t f t 1 f 1186 "1083" 100 0 0 1
DESCR("convert time to interval"); DESCR("convert time to interval");
DATA(insert OID = 1371 ( date PGUID 14 f t t t 1 f 1082 "1082" 100 0 0 100 "select $1" - )); DATA(insert OID = 1371 ( date PGUID 14 f t t t 1 f 1082 "1082" 100 0 0 100 "select $1" - ));
DESCR("convert (noop)"); DESCR("convert (noop)");
DATA(insert OID = 1372 ( char_length PGUID 11 f t t t 1 f 23 "1042" 100 0 0 100 bpcharlen - )); DATA(insert OID = 1372 ( char_length PGUID 12 f t t t 1 f 23 "1042" 100 0 0 100 bpcharlen - ));
DESCR("character length"); DESCR("character length");
DATA(insert OID = 1373 ( char_length PGUID 11 f t t t 1 f 23 "1043" 100 0 0 100 varcharlen - )); DATA(insert OID = 1373 ( char_length PGUID 12 f t t t 1 f 23 "1043" 100 0 0 100 varcharlen - ));
DESCR("character length"); DESCR("character length");
DATA(insert OID = 1374 ( octet_length PGUID 12 f t t t 1 f 23 "25" 100 0 0 100 textoctetlen - )); DATA(insert OID = 1374 ( octet_length PGUID 12 f t t t 1 f 23 "25" 100 0 0 100 textoctetlen - ));
DESCR("octet length"); DESCR("octet length");
DATA(insert OID = 1375 ( octet_length PGUID 11 f t t t 1 f 23 "1042" 100 0 0 100 bpcharoctetlen - )); DATA(insert OID = 1375 ( octet_length PGUID 12 f t t t 1 f 23 "1042" 100 0 0 100 bpcharoctetlen - ));
DESCR("octet length"); DESCR("octet length");
DATA(insert OID = 1376 ( octet_length PGUID 11 f t t t 1 f 23 "1043" 100 0 0 100 varcharoctetlen - )); DATA(insert OID = 1376 ( octet_length PGUID 12 f t t t 1 f 23 "1043" 100 0 0 100 varcharoctetlen - ));
DESCR("octet length"); DESCR("octet length");
DATA(insert OID = 1377 ( time_larger PGUID 12 f t t t 2 f 1083 "1083 1083" 100 0 0 100 time_larger - )); DATA(insert OID = 1377 ( time_larger PGUID 12 f t t t 2 f 1083 "1083 1083" 100 0 0 100 time_larger - ));
...@@ -2313,11 +2313,11 @@ DATA(insert OID = 1702 ( numeric_out PGUID 12 f t t t 1 f 23 "0" 100 0 0 100 ...@@ -2313,11 +2313,11 @@ DATA(insert OID = 1702 ( numeric_out PGUID 12 f t t t 1 f 23 "0" 100 0 0 100
DESCR("(internal)"); DESCR("(internal)");
DATA(insert OID = 1703 ( numeric PGUID 12 f t t t 2 f 1700 "1700 23" 100 0 0 100 numeric - )); DATA(insert OID = 1703 ( numeric PGUID 12 f t t t 2 f 1700 "1700 23" 100 0 0 100 numeric - ));
DESCR("adjust numeric to typmod precision/scale"); DESCR("adjust numeric to typmod precision/scale");
DATA(insert OID = 1704 ( numeric_abs PGUID 11 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_abs - )); DATA(insert OID = 1704 ( numeric_abs PGUID 12 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_abs - ));
DESCR("absolute value"); DESCR("absolute value");
DATA(insert OID = 1705 ( abs PGUID 11 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_abs - )); DATA(insert OID = 1705 ( abs PGUID 12 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_abs - ));
DESCR("absolute value"); DESCR("absolute value");
DATA(insert OID = 1706 ( sign PGUID 11 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_sign - )); DATA(insert OID = 1706 ( sign PGUID 12 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_sign - ));
DESCR("sign of value"); DESCR("sign of value");
DATA(insert OID = 1707 ( round PGUID 12 f t t t 2 f 1700 "1700 23" 100 0 0 100 numeric_round - )); DATA(insert OID = 1707 ( round PGUID 12 f t t t 2 f 1700 "1700 23" 100 0 0 100 numeric_round - ));
DESCR("value rounded to 'scale'"); DESCR("value rounded to 'scale'");
...@@ -2327,79 +2327,79 @@ DATA(insert OID = 1709 ( trunc PGUID 12 f t t t 2 f 1700 "1700 23" 100 0 0 1 ...@@ -2327,79 +2327,79 @@ DATA(insert OID = 1709 ( trunc PGUID 12 f t t t 2 f 1700 "1700 23" 100 0 0 1
DESCR("value truncated to 'scale'"); DESCR("value truncated to 'scale'");
DATA(insert OID = 1710 ( trunc PGUID 14 f t t t 1 f 1700 "1700" 100 0 0 100 "select trunc($1,0)" - )); DATA(insert OID = 1710 ( trunc PGUID 14 f t t t 1 f 1700 "1700" 100 0 0 100 "select trunc($1,0)" - ));
DESCR("value truncated to 'scale' of zero"); DESCR("value truncated to 'scale' of zero");
DATA(insert OID = 1711 ( ceil PGUID 11 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_ceil - )); DATA(insert OID = 1711 ( ceil PGUID 12 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_ceil - ));
DESCR("smallest integer >= value"); DESCR("smallest integer >= value");
DATA(insert OID = 1712 ( floor PGUID 11 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_floor - )); DATA(insert OID = 1712 ( floor PGUID 12 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_floor - ));
DESCR("largest integer <= value"); DESCR("largest integer <= value");
DATA(insert OID = 1718 ( numeric_eq PGUID 11 f t t t 2 f 16 "1700 1700" 100 0 0 100 numeric_eq - )); DATA(insert OID = 1718 ( numeric_eq PGUID 12 f t t t 2 f 16 "1700 1700" 100 0 0 100 numeric_eq - ));
DESCR("equal"); DESCR("equal");
DATA(insert OID = 1719 ( numeric_ne PGUID 11 f t t t 2 f 16 "1700 1700" 100 0 0 100 numeric_ne - )); DATA(insert OID = 1719 ( numeric_ne PGUID 12 f t t t 2 f 16 "1700 1700" 100 0 0 100 numeric_ne - ));
DESCR("not equal"); DESCR("not equal");
DATA(insert OID = 1720 ( numeric_gt PGUID 11 f t t t 2 f 16 "1700 1700" 100 0 0 100 numeric_gt - )); DATA(insert OID = 1720 ( numeric_gt PGUID 12 f t t t 2 f 16 "1700 1700" 100 0 0 100 numeric_gt - ));
DESCR("greater-than"); DESCR("greater-than");
DATA(insert OID = 1721 ( numeric_ge PGUID 11 f t t t 2 f 16 "1700 1700" 100 0 0 100 numeric_ge - )); DATA(insert OID = 1721 ( numeric_ge PGUID 12 f t t t 2 f 16 "1700 1700" 100 0 0 100 numeric_ge - ));
DESCR("greater-than-or-equal"); DESCR("greater-than-or-equal");
DATA(insert OID = 1722 ( numeric_lt PGUID 11 f t t t 2 f 16 "1700 1700" 100 0 0 100 numeric_lt - )); DATA(insert OID = 1722 ( numeric_lt PGUID 12 f t t t 2 f 16 "1700 1700" 100 0 0 100 numeric_lt - ));
DESCR("lower-than"); DESCR("lower-than");
DATA(insert OID = 1723 ( numeric_le PGUID 11 f t t t 2 f 16 "1700 1700" 100 0 0 100 numeric_le - )); DATA(insert OID = 1723 ( numeric_le PGUID 12 f t t t 2 f 16 "1700 1700" 100 0 0 100 numeric_le - ));
DESCR("lower-than-or-equal"); DESCR("lower-than-or-equal");
DATA(insert OID = 1724 ( numeric_add PGUID 11 f t t t 2 f 1700 "1700 1700" 100 0 0 100 numeric_add - )); DATA(insert OID = 1724 ( numeric_add PGUID 12 f t t t 2 f 1700 "1700 1700" 100 0 0 100 numeric_add - ));
DESCR("addition"); DESCR("addition");
DATA(insert OID = 1725 ( numeric_sub PGUID 11 f t t t 2 f 1700 "1700 1700" 100 0 0 100 numeric_sub - )); DATA(insert OID = 1725 ( numeric_sub PGUID 12 f t t t 2 f 1700 "1700 1700" 100 0 0 100 numeric_sub - ));
DESCR("subtract"); DESCR("subtract");
DATA(insert OID = 1726 ( numeric_mul PGUID 11 f t t t 2 f 1700 "1700 1700" 100 0 0 100 numeric_mul - )); DATA(insert OID = 1726 ( numeric_mul PGUID 12 f t t t 2 f 1700 "1700 1700" 100 0 0 100 numeric_mul - ));
DESCR("multiply"); DESCR("multiply");
DATA(insert OID = 1727 ( numeric_div PGUID 11 f t t t 2 f 1700 "1700 1700" 100 0 0 100 numeric_div - )); DATA(insert OID = 1727 ( numeric_div PGUID 12 f t t t 2 f 1700 "1700 1700" 100 0 0 100 numeric_div - ));
DESCR("divide"); DESCR("divide");
DATA(insert OID = 1728 ( mod PGUID 11 f t t t 2 f 1700 "1700 1700" 100 0 0 100 numeric_mod - )); DATA(insert OID = 1728 ( mod PGUID 12 f t t t 2 f 1700 "1700 1700" 100 0 0 100 numeric_mod - ));
DESCR("modulus"); DESCR("modulus");
DATA(insert OID = 1729 ( numeric_mod PGUID 11 f t t t 2 f 1700 "1700 1700" 100 0 0 100 numeric_mod - )); DATA(insert OID = 1729 ( numeric_mod PGUID 12 f t t t 2 f 1700 "1700 1700" 100 0 0 100 numeric_mod - ));
DESCR("modulus"); DESCR("modulus");
DATA(insert OID = 1730 ( sqrt PGUID 11 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_sqrt - )); DATA(insert OID = 1730 ( sqrt PGUID 12 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_sqrt - ));
DESCR("square root"); DESCR("square root");
DATA(insert OID = 1731 ( numeric_sqrt PGUID 11 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_sqrt - )); DATA(insert OID = 1731 ( numeric_sqrt PGUID 12 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_sqrt - ));
DESCR("square root"); DESCR("square root");
DATA(insert OID = 1732 ( exp PGUID 11 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_exp - )); DATA(insert OID = 1732 ( exp PGUID 12 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_exp - ));
DESCR("e raised to the power of n"); DESCR("e raised to the power of n");
DATA(insert OID = 1733 ( numeric_exp PGUID 11 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_exp - )); DATA(insert OID = 1733 ( numeric_exp PGUID 12 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_exp - ));
DESCR("e raised to the power of n"); DESCR("e raised to the power of n");
DATA(insert OID = 1734 ( ln PGUID 11 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_ln - )); DATA(insert OID = 1734 ( ln PGUID 12 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_ln - ));
DESCR("natural logarithm of n"); DESCR("natural logarithm of n");
DATA(insert OID = 1735 ( numeric_ln PGUID 11 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_ln - )); DATA(insert OID = 1735 ( numeric_ln PGUID 12 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_ln - ));
DESCR("natural logarithm of n"); DESCR("natural logarithm of n");
DATA(insert OID = 1736 ( log PGUID 11 f t t t 2 f 1700 "1700 1700" 100 0 0 100 numeric_log - )); DATA(insert OID = 1736 ( log PGUID 12 f t t t 2 f 1700 "1700 1700" 100 0 0 100 numeric_log - ));
DESCR("logarithm base m of n"); DESCR("logarithm base m of n");
DATA(insert OID = 1737 ( numeric_log PGUID 11 f t t t 2 f 1700 "1700 1700" 100 0 0 100 numeric_log - )); DATA(insert OID = 1737 ( numeric_log PGUID 12 f t t t 2 f 1700 "1700 1700" 100 0 0 100 numeric_log - ));
DESCR("logarithm base m of n"); DESCR("logarithm base m of n");
DATA(insert OID = 1738 ( pow PGUID 11 f t t t 2 f 1700 "1700 1700" 100 0 0 100 numeric_power - )); DATA(insert OID = 1738 ( pow PGUID 12 f t t t 2 f 1700 "1700 1700" 100 0 0 100 numeric_power - ));
DESCR("m raised to the power of n"); DESCR("m raised to the power of n");
DATA(insert OID = 1739 ( numeric_power PGUID 11 f t t t 2 f 1700 "1700 1700" 100 0 0 100 numeric_power - )); DATA(insert OID = 1739 ( numeric_power PGUID 12 f t t t 2 f 1700 "1700 1700" 100 0 0 100 numeric_power - ));
DESCR("m raised to the power of n"); DESCR("m raised to the power of n");
DATA(insert OID = 1740 ( numeric PGUID 12 f t t t 1 f 1700 "23" 100 0 0 100 int4_numeric - )); DATA(insert OID = 1740 ( numeric PGUID 12 f t t t 1 f 1700 "23" 100 0 0 100 int4_numeric - ));
DESCR("(internal)"); DESCR("(internal)");
DATA(insert OID = 1741 ( log PGUID 14 f t t t 1 f 1700 "1700" 100 0 0 100 "select log(10, $1)" - )); DATA(insert OID = 1741 ( log PGUID 14 f t t t 1 f 1700 "1700" 100 0 0 100 "select log(10, $1)" - ));
DESCR("logarithm base 10 of n"); DESCR("logarithm base 10 of n");
DATA(insert OID = 1742 ( numeric PGUID 11 f t t t 1 f 1700 "700" 100 0 0 100 float4_numeric - )); DATA(insert OID = 1742 ( numeric PGUID 12 f t t t 1 f 1700 "700" 100 0 0 100 float4_numeric - ));
DESCR("(internal)"); DESCR("(internal)");
DATA(insert OID = 1743 ( numeric PGUID 11 f t t t 1 f 1700 "701" 100 0 0 100 float8_numeric - )); DATA(insert OID = 1743 ( numeric PGUID 12 f t t t 1 f 1700 "701" 100 0 0 100 float8_numeric - ));
DESCR("(internal)"); DESCR("(internal)");
DATA(insert OID = 1744 ( int4 PGUID 11 f t t t 1 f 23 "1700" 100 0 0 100 numeric_int4 - )); DATA(insert OID = 1744 ( int4 PGUID 12 f t t t 1 f 23 "1700" 100 0 0 100 numeric_int4 - ));
DESCR("(internal)"); DESCR("(internal)");
DATA(insert OID = 1745 ( float4 PGUID 11 f t t t 1 f 700 "1700" 100 0 0 100 numeric_float4 - )); DATA(insert OID = 1745 ( float4 PGUID 12 f t t t 1 f 700 "1700" 100 0 0 100 numeric_float4 - ));
DESCR("(internal)"); DESCR("(internal)");
DATA(insert OID = 1746 ( float8 PGUID 11 f t t t 1 f 701 "1700" 100 0 0 100 numeric_float8 - )); DATA(insert OID = 1746 ( float8 PGUID 12 f t t t 1 f 701 "1700" 100 0 0 100 numeric_float8 - ));
DESCR("(internal)"); DESCR("(internal)");
DATA(insert OID = 1764 ( numeric_inc PGUID 11 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_inc - )); DATA(insert OID = 1764 ( numeric_inc PGUID 12 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_inc - ));
DESCR("increment by one"); DESCR("increment by one");
DATA(insert OID = 1766 ( numeric_smaller PGUID 11 f t t t 2 f 1700 "1700 1700" 100 0 0 100 numeric_smaller - )); DATA(insert OID = 1766 ( numeric_smaller PGUID 12 f t t t 2 f 1700 "1700 1700" 100 0 0 100 numeric_smaller - ));
DESCR("smaller of two numbers"); DESCR("smaller of two numbers");
DATA(insert OID = 1767 ( numeric_larger PGUID 11 f t t t 2 f 1700 "1700 1700" 100 0 0 100 numeric_larger - )); DATA(insert OID = 1767 ( numeric_larger PGUID 12 f t t t 2 f 1700 "1700 1700" 100 0 0 100 numeric_larger - ));
DESCR("larger of two numbers"); DESCR("larger of two numbers");
DATA(insert OID = 1769 ( numeric_cmp PGUID 11 f t t t 2 f 23 "1700 1700" 100 0 0 100 numeric_cmp - )); DATA(insert OID = 1769 ( numeric_cmp PGUID 12 f t t t 2 f 23 "1700 1700" 100 0 0 100 numeric_cmp - ));
DESCR("compare two numbers"); DESCR("compare two numbers");
DATA(insert OID = 1771 ( numeric_uminus PGUID 11 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_uminus - )); DATA(insert OID = 1771 ( numeric_uminus PGUID 12 f t t t 1 f 1700 "1700" 100 0 0 100 numeric_uminus - ));
DESCR("negate"); DESCR("negate");
DATA(insert OID = 1779 ( int8 PGUID 11 f t t t 1 f 20 "1700" 100 0 0 100 numeric_int8 - )); DATA(insert OID = 1779 ( int8 PGUID 12 f t t t 1 f 20 "1700" 100 0 0 100 numeric_int8 - ));
DESCR("(internal)"); DESCR("(internal)");
DATA(insert OID = 1781 ( numeric PGUID 12 f t t t 1 f 1700 "20" 100 0 0 100 int8_numeric - )); DATA(insert OID = 1781 ( numeric PGUID 12 f t t t 1 f 1700 "20" 100 0 0 100 int8_numeric - ));
DESCR("(internal)"); DESCR("(internal)");
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: pg_type.h,v 1.93 2000/07/22 03:34:28 tgl Exp $ * $Id: pg_type.h,v 1.94 2000/07/29 03:26:43 tgl Exp $
* *
* NOTES * NOTES
* the genbki.sh script reads this file and generates .bki * the genbki.sh script reads this file and generates .bki
...@@ -174,7 +174,7 @@ DATA(insert OID = 16 ( bool PGUID 1 1 t b t \054 0 0 boolin boolout bool ...@@ -174,7 +174,7 @@ DATA(insert OID = 16 ( bool PGUID 1 1 t b t \054 0 0 boolin boolout bool
DESCR("boolean, 'true'/'false'"); DESCR("boolean, 'true'/'false'");
#define BOOLOID 16 #define BOOLOID 16
DATA(insert OID = 17 ( bytea PGUID -1 -1 f b t \054 0 0 byteain byteaout byteain byteaout i p _null_ )); DATA(insert OID = 17 ( bytea PGUID -1 -1 f b t \054 0 0 byteain byteaout byteain byteaout i x _null_ ));
DESCR("variable-length string, binary values escaped"); DESCR("variable-length string, binary values escaped");
#define BYTEAOID 17 #define BYTEAOID 17
...@@ -368,10 +368,10 @@ DATA(insert OID = 1034 ( _aclitem PGUID -1 -1 f b t \054 0 1033 array_in array ...@@ -368,10 +368,10 @@ DATA(insert OID = 1034 ( _aclitem PGUID -1 -1 f b t \054 0 1033 array_in array
DATA(insert OID = 1040 ( _macaddr PGUID -1 -1 f b t \054 0 829 array_in array_out array_in array_out i x _null_ )); DATA(insert OID = 1040 ( _macaddr PGUID -1 -1 f b t \054 0 829 array_in array_out array_in array_out i x _null_ ));
DATA(insert OID = 1041 ( _inet PGUID -1 -1 f b t \054 0 869 array_in array_out array_in array_out i x _null_ )); DATA(insert OID = 1041 ( _inet PGUID -1 -1 f b t \054 0 869 array_in array_out array_in array_out i x _null_ ));
DATA(insert OID = 651 ( _cidr PGUID -1 -1 f b t \054 0 650 array_in array_out array_in array_out i x _null_ )); DATA(insert OID = 651 ( _cidr PGUID -1 -1 f b t \054 0 650 array_in array_out array_in array_out i x _null_ ));
DATA(insert OID = 1042 ( bpchar PGUID -1 -1 f b t \054 0 0 bpcharin bpcharout bpcharin bpcharout i p _null_ )); DATA(insert OID = 1042 ( bpchar PGUID -1 -1 f b t \054 0 0 bpcharin bpcharout bpcharin bpcharout i x _null_ ));
DESCR("char(length), blank-padded string, fixed storage length"); DESCR("char(length), blank-padded string, fixed storage length");
#define BPCHAROID 1042 #define BPCHAROID 1042
DATA(insert OID = 1043 ( varchar PGUID -1 -1 f b t \054 0 0 varcharin varcharout varcharin varcharout i p _null_ )); DATA(insert OID = 1043 ( varchar PGUID -1 -1 f b t \054 0 0 varcharin varcharout varcharin varcharout i x _null_ ));
DESCR("varchar(length), non-blank-padded string, variable storage length"); DESCR("varchar(length), non-blank-padded string, variable storage length");
#define VARCHAROID 1043 #define VARCHAROID 1043
...@@ -417,7 +417,7 @@ DESCR("variable-length string, stored compressed"); ...@@ -417,7 +417,7 @@ DESCR("variable-length string, stored compressed");
#define LZTEXTOID 1625 #define LZTEXTOID 1625
/* OIDS 1700 - 1799 */ /* OIDS 1700 - 1799 */
DATA(insert OID = 1700 ( numeric PGUID -1 -1 f b t \054 0 0 numeric_in numeric_out numeric_in numeric_out i p _null_ )); DATA(insert OID = 1700 ( numeric PGUID -1 -1 f b t \054 0 0 numeric_in numeric_out numeric_in numeric_out i m _null_ ));
DESCR("numeric(precision, decimal), arbitrary precision number"); DESCR("numeric(precision, decimal), arbitrary precision number");
#define NUMERICOID 1700 #define NUMERICOID 1700
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: fmgr.h,v 1.8 2000/07/12 02:37:25 tgl Exp $ * $Id: fmgr.h,v 1.9 2000/07/29 03:26:47 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -185,6 +185,7 @@ extern struct varlena * pg_detoast_datum_copy(struct varlena * datum); ...@@ -185,6 +185,7 @@ extern struct varlena * pg_detoast_datum_copy(struct varlena * datum);
/* Macros for returning results of standard types */ /* Macros for returning results of standard types */
#define PG_RETURN_DATUM(x) return (x)
#define PG_RETURN_INT32(x) return Int32GetDatum(x) #define PG_RETURN_INT32(x) return Int32GetDatum(x)
#define PG_RETURN_UINT32(x) return UInt32GetDatum(x) #define PG_RETURN_UINT32(x) return UInt32GetDatum(x)
#define PG_RETURN_INT16(x) return Int16GetDatum(x) #define PG_RETURN_INT16(x) return Int16GetDatum(x)
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: builtins.h,v 1.124 2000/07/17 03:05:32 tgl Exp $ * $Id: builtins.h,v 1.125 2000/07/29 03:26:51 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -400,32 +400,32 @@ extern Datum bpchar(PG_FUNCTION_ARGS); ...@@ -400,32 +400,32 @@ extern Datum bpchar(PG_FUNCTION_ARGS);
extern Datum _bpchar(PG_FUNCTION_ARGS); extern Datum _bpchar(PG_FUNCTION_ARGS);
extern Datum char_bpchar(PG_FUNCTION_ARGS); extern Datum char_bpchar(PG_FUNCTION_ARGS);
extern Datum bpchar_char(PG_FUNCTION_ARGS); extern Datum bpchar_char(PG_FUNCTION_ARGS);
extern char *name_bpchar(NameData *s); extern Datum name_bpchar(PG_FUNCTION_ARGS);
extern NameData *bpchar_name(char *s); extern Datum bpchar_name(PG_FUNCTION_ARGS);
extern bool bpchareq(char *arg1, char *arg2); extern Datum bpchareq(PG_FUNCTION_ARGS);
extern bool bpcharne(char *arg1, char *arg2); extern Datum bpcharne(PG_FUNCTION_ARGS);
extern bool bpcharlt(char *arg1, char *arg2); extern Datum bpcharlt(PG_FUNCTION_ARGS);
extern bool bpcharle(char *arg1, char *arg2); extern Datum bpcharle(PG_FUNCTION_ARGS);
extern bool bpchargt(char *arg1, char *arg2); extern Datum bpchargt(PG_FUNCTION_ARGS);
extern bool bpcharge(char *arg1, char *arg2); extern Datum bpcharge(PG_FUNCTION_ARGS);
extern int32 bpcharcmp(char *arg1, char *arg2); extern Datum bpcharcmp(PG_FUNCTION_ARGS);
extern int32 bpcharlen(char *arg); extern Datum bpcharlen(PG_FUNCTION_ARGS);
extern int32 bpcharoctetlen(char *arg); extern Datum bpcharoctetlen(PG_FUNCTION_ARGS);
extern Datum hashbpchar(PG_FUNCTION_ARGS); extern Datum hashbpchar(PG_FUNCTION_ARGS);
extern Datum varcharin(PG_FUNCTION_ARGS); extern Datum varcharin(PG_FUNCTION_ARGS);
extern Datum varcharout(PG_FUNCTION_ARGS); extern Datum varcharout(PG_FUNCTION_ARGS);
extern Datum varchar(PG_FUNCTION_ARGS); extern Datum varchar(PG_FUNCTION_ARGS);
extern Datum _varchar(PG_FUNCTION_ARGS); extern Datum _varchar(PG_FUNCTION_ARGS);
extern bool varchareq(char *arg1, char *arg2); extern Datum varchareq(PG_FUNCTION_ARGS);
extern bool varcharne(char *arg1, char *arg2); extern Datum varcharne(PG_FUNCTION_ARGS);
extern bool varcharlt(char *arg1, char *arg2); extern Datum varcharlt(PG_FUNCTION_ARGS);
extern bool varcharle(char *arg1, char *arg2); extern Datum varcharle(PG_FUNCTION_ARGS);
extern bool varchargt(char *arg1, char *arg2); extern Datum varchargt(PG_FUNCTION_ARGS);
extern bool varcharge(char *arg1, char *arg2); extern Datum varcharge(PG_FUNCTION_ARGS);
extern int32 varcharcmp(char *arg1, char *arg2); extern Datum varcharcmp(PG_FUNCTION_ARGS);
extern int32 varcharlen(char *arg); extern Datum varcharlen(PG_FUNCTION_ARGS);
extern int32 varcharoctetlen(char *arg); extern Datum varcharoctetlen(PG_FUNCTION_ARGS);
/* varlena.c */ /* varlena.c */
extern Datum textin(PG_FUNCTION_ARGS); extern Datum textin(PG_FUNCTION_ARGS);
...@@ -447,9 +447,9 @@ extern Datum name_text(PG_FUNCTION_ARGS); ...@@ -447,9 +447,9 @@ extern Datum name_text(PG_FUNCTION_ARGS);
extern Datum text_name(PG_FUNCTION_ARGS); extern Datum text_name(PG_FUNCTION_ARGS);
extern int varstr_cmp(char *arg1, int len1, char *arg2, int len2); extern int varstr_cmp(char *arg1, int len1, char *arg2, int len2);
extern bytea *byteain(char *inputText); extern Datum byteain(PG_FUNCTION_ARGS);
extern char *byteaout(bytea *vlena); extern Datum byteaout(PG_FUNCTION_ARGS);
extern int32 byteaoctetlen(bytea *v); extern Datum byteaoctetlen(PG_FUNCTION_ARGS);
extern Datum byteaGetByte(PG_FUNCTION_ARGS); extern Datum byteaGetByte(PG_FUNCTION_ARGS);
extern Datum byteaGetBit(PG_FUNCTION_ARGS); extern Datum byteaGetBit(PG_FUNCTION_ARGS);
extern Datum byteaSetByte(PG_FUNCTION_ARGS); extern Datum byteaSetByte(PG_FUNCTION_ARGS);
...@@ -527,43 +527,43 @@ extern Datum macaddr_manuf(PG_FUNCTION_ARGS); ...@@ -527,43 +527,43 @@ extern Datum macaddr_manuf(PG_FUNCTION_ARGS);
extern Datum numeric_in(PG_FUNCTION_ARGS); extern Datum numeric_in(PG_FUNCTION_ARGS);
extern Datum numeric_out(PG_FUNCTION_ARGS); extern Datum numeric_out(PG_FUNCTION_ARGS);
extern Datum numeric(PG_FUNCTION_ARGS); extern Datum numeric(PG_FUNCTION_ARGS);
extern Numeric numeric_abs(Numeric num); extern Datum numeric_abs(PG_FUNCTION_ARGS);
extern Numeric numeric_uminus(Numeric num); extern Datum numeric_uminus(PG_FUNCTION_ARGS);
extern Numeric numeric_sign(Numeric num); extern Datum numeric_sign(PG_FUNCTION_ARGS);
extern Datum numeric_round(PG_FUNCTION_ARGS); extern Datum numeric_round(PG_FUNCTION_ARGS);
extern Datum numeric_trunc(PG_FUNCTION_ARGS); extern Datum numeric_trunc(PG_FUNCTION_ARGS);
extern Numeric numeric_ceil(Numeric num); extern Datum numeric_ceil(PG_FUNCTION_ARGS);
extern Numeric numeric_floor(Numeric num); extern Datum numeric_floor(PG_FUNCTION_ARGS);
extern int32 numeric_cmp(Numeric num1, Numeric num2); extern Datum numeric_cmp(PG_FUNCTION_ARGS);
extern bool numeric_eq(Numeric num1, Numeric num2); extern Datum numeric_eq(PG_FUNCTION_ARGS);
extern bool numeric_ne(Numeric num1, Numeric num2); extern Datum numeric_ne(PG_FUNCTION_ARGS);
extern bool numeric_gt(Numeric num1, Numeric num2); extern Datum numeric_gt(PG_FUNCTION_ARGS);
extern bool numeric_ge(Numeric num1, Numeric num2); extern Datum numeric_ge(PG_FUNCTION_ARGS);
extern bool numeric_lt(Numeric num1, Numeric num2); extern Datum numeric_lt(PG_FUNCTION_ARGS);
extern bool numeric_le(Numeric num1, Numeric num2); extern Datum numeric_le(PG_FUNCTION_ARGS);
extern Numeric numeric_add(Numeric num1, Numeric num2); extern Datum numeric_add(PG_FUNCTION_ARGS);
extern Numeric numeric_sub(Numeric num1, Numeric num2); extern Datum numeric_sub(PG_FUNCTION_ARGS);
extern Numeric numeric_mul(Numeric num1, Numeric num2); extern Datum numeric_mul(PG_FUNCTION_ARGS);
extern Numeric numeric_div(Numeric num1, Numeric num2); extern Datum numeric_div(PG_FUNCTION_ARGS);
extern Numeric numeric_mod(Numeric num1, Numeric num2); extern Datum numeric_mod(PG_FUNCTION_ARGS);
extern Numeric numeric_inc(Numeric num); extern Datum numeric_inc(PG_FUNCTION_ARGS);
extern Numeric numeric_smaller(Numeric num1, Numeric num2); extern Datum numeric_smaller(PG_FUNCTION_ARGS);
extern Numeric numeric_larger(Numeric num1, Numeric num2); extern Datum numeric_larger(PG_FUNCTION_ARGS);
extern Numeric numeric_sqrt(Numeric num); extern Datum numeric_sqrt(PG_FUNCTION_ARGS);
extern Numeric numeric_exp(Numeric num); extern Datum numeric_exp(PG_FUNCTION_ARGS);
extern Numeric numeric_ln(Numeric num); extern Datum numeric_ln(PG_FUNCTION_ARGS);
extern Numeric numeric_log(Numeric num1, Numeric num2); extern Datum numeric_log(PG_FUNCTION_ARGS);
extern Numeric numeric_power(Numeric num1, Numeric num2); extern Datum numeric_power(PG_FUNCTION_ARGS);
extern Datum int4_numeric(PG_FUNCTION_ARGS); extern Datum int4_numeric(PG_FUNCTION_ARGS);
extern int32 numeric_int4(Numeric num); extern Datum numeric_int4(PG_FUNCTION_ARGS);
extern Datum int8_numeric(PG_FUNCTION_ARGS); extern Datum int8_numeric(PG_FUNCTION_ARGS);
extern int64 *numeric_int8(Numeric num); extern Datum numeric_int8(PG_FUNCTION_ARGS);
extern Datum int2_numeric(PG_FUNCTION_ARGS); extern Datum int2_numeric(PG_FUNCTION_ARGS);
extern Datum numeric_int2(PG_FUNCTION_ARGS); extern Datum numeric_int2(PG_FUNCTION_ARGS);
extern Numeric float8_numeric(float64 val); extern Datum float8_numeric(PG_FUNCTION_ARGS);
extern float64 numeric_float8(Numeric num); extern Datum numeric_float8(PG_FUNCTION_ARGS);
extern Numeric float4_numeric(float32 val); extern Datum float4_numeric(PG_FUNCTION_ARGS);
extern float32 numeric_float4(Numeric num); extern Datum numeric_float4(PG_FUNCTION_ARGS);
extern Datum numeric_accum(PG_FUNCTION_ARGS); extern Datum numeric_accum(PG_FUNCTION_ARGS);
extern Datum int2_accum(PG_FUNCTION_ARGS); extern Datum int2_accum(PG_FUNCTION_ARGS);
extern Datum int4_accum(PG_FUNCTION_ARGS); extern Datum int4_accum(PG_FUNCTION_ARGS);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment