#include "postgres.h"#include "utils/datum.h"
Go to the source code of this file.
Functions | |
| Size | datumGetSize (Datum value, bool typByVal, int typLen) |
| Datum | datumCopy (Datum value, bool typByVal, int typLen) |
| bool | datumIsEqual (Datum value1, Datum value2, bool typByVal, int typLen) |
Definition at line 115 of file datum.c.
References DatumGetPointer, datumGetSize(), NULL, palloc(), and PointerGetDatum.
Referenced by _copyConst(), accumArrayResult(), advance_transition_function(), advance_windowaggregate(), collectMatchBitmap(), compute_array_stats(), compute_index_stats(), compute_minimal_stats(), compute_scalar_stats(), copyParamList(), eval_const_expressions_mutator(), eval_windowaggregates(), eval_windowfunction(), evaluate_expr(), exec_assign_value(), exec_eval_using_params(), exec_stmt_block(), ExecWindowAgg(), finalize_aggregate(), finalize_windowaggregate(), get_actual_variable_range(), get_attstatsslot(), get_variable_range(), getDatumCopy(), initialize_aggregates(), initialize_windowaggregate(), postquel_get_single_result(), spg_text_inner_consistent(), spgWalk(), tuplesort_getdatum(), and tuplesort_putdatum().
{
Datum res;
if (typByVal)
res = value;
else
{
Size realSize;
char *s;
if (DatumGetPointer(value) == NULL)
return PointerGetDatum(NULL);
realSize = datumGetSize(value, typByVal, typLen);
s = (char *) palloc(realSize);
memcpy(s, DatumGetPointer(value), realSize);
res = PointerGetDatum(s);
}
return res;
}
Definition at line 55 of file datum.c.
References Assert, DatumGetPointer, elog, ereport, errcode(), errmsg(), ERROR, PointerIsValid, and VARSIZE_ANY.
Referenced by _outDatum(), datumCopy(), datumIsEqual(), plpgsql_exec_function(), and writetup_datum().
{
Size size;
if (typByVal)
{
/* Pass-by-value types are always fixed-length */
Assert(typLen > 0 && typLen <= sizeof(Datum));
size = (Size) typLen;
}
else
{
if (typLen > 0)
{
/* Fixed-length pass-by-ref type */
size = (Size) typLen;
}
else if (typLen == -1)
{
/* It is a varlena datatype */
struct varlena *s = (struct varlena *) DatumGetPointer(value);
if (!PointerIsValid(s))
ereport(ERROR,
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("invalid Datum pointer")));
size = (Size) VARSIZE_ANY(s);
}
else if (typLen == -2)
{
/* It is a cstring datatype */
char *s = (char *) DatumGetPointer(value);
if (!PointerIsValid(s))
ereport(ERROR,
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("invalid Datum pointer")));
size = (Size) (strlen(s) + 1);
}
else
{
elog(ERROR, "invalid typLen: %d", typLen);
size = 0; /* keep compiler quiet */
}
}
return size;
}
Definition at line 175 of file datum.c.
References DatumGetPointer, datumGetSize(), memcmp(), s1, and s2.
Referenced by _equalConst(), heap_tuple_attr_equals(), and stringTypeDatum().
{
bool res;
if (typByVal)
{
/*
* just compare the two datums. NOTE: just comparing "len" bytes will
* not do the work, because we do not know how these bytes are aligned
* inside the "Datum". We assume instead that any given datatype is
* consistent about how it fills extraneous bits in the Datum.
*/
res = (value1 == value2);
}
else
{
Size size1,
size2;
char *s1,
*s2;
/*
* Compare the bytes pointed by the pointers stored in the datums.
*/
size1 = datumGetSize(value1, typByVal, typLen);
size2 = datumGetSize(value2, typByVal, typLen);
if (size1 != size2)
return false;
s1 = (char *) DatumGetPointer(value1);
s2 = (char *) DatumGetPointer(value2);
res = (memcmp(s1, s2, size1) == 0);
}
return res;
}
1.7.1