diff --git a/src/rrtimeslice.c b/src/rrtimeslice.c
index b08662292178e979c71c1d1c9e41bcb9855d6fe8..7207dea04bdab2a0414360197209bd7d4a253165 100644 (file)
--- a/src/rrtimeslice.c
+++ b/src/rrtimeslice.c
PG_FUNCTION_INFO_V1(rrtimeslice_typmodout);
PG_FUNCTION_INFO_V1(rrtimeslice_to_rrtimeslice);
+PG_FUNCTION_INFO_V1(rrtimeslice_to_timestamp);
-PG_FUNCTION_INFO_V1(rrtimeslice_eq);
-PG_FUNCTION_INFO_V1(rrtimeslice_ne);
-PG_FUNCTION_INFO_V1(rrtimeslice_lt);
-PG_FUNCTION_INFO_V1(rrtimeslice_gt);
-PG_FUNCTION_INFO_V1(rrtimeslice_le);
-PG_FUNCTION_INFO_V1(rrtimeslice_ge);
-PG_FUNCTION_INFO_V1(rrtimeslice_cmp);
-PG_FUNCTION_INFO_V1(rrtimeslice_hash);
+PG_FUNCTION_INFO_V1(rrtimeslice_seq_eq);
+PG_FUNCTION_INFO_V1(rrtimeslice_seq_ne);
+PG_FUNCTION_INFO_V1(rrtimeslice_seq_lt);
+PG_FUNCTION_INFO_V1(rrtimeslice_seq_gt);
+PG_FUNCTION_INFO_V1(rrtimeslice_seq_le);
+PG_FUNCTION_INFO_V1(rrtimeslice_seq_ge);
+PG_FUNCTION_INFO_V1(rrtimeslice_seq_cmp);
+PG_FUNCTION_INFO_V1(rrtimeslice_seq_hash);
/*
* public API
PG_RETURN_RRTIMESLICE_P(tslice);
} /* rrtimeslice_to_rrtimeslice */
+Datum
+rrtimeslice_to_timestamp(PG_FUNCTION_ARGS)
+{
+ rrtimeslice_t *tslice;
+
+ if (PG_NARGS() != 1)
+ ereport(ERROR, (
+ errmsg("rrtimeslice_to_timestamp() "
+ "expects one argument"),
+ errhint("Usage: rrtimeslice_to_timestamp"
+ "(rrtimeslice)")
+ ));
+
+ tslice = PG_GETARG_RRTIMESLICE_P(0);
+ PG_RETURN_TIMESTAMP(tslice->tstamp);
+} /* rrtimeslice_to_timestamp */
+
int
-rrtimeslice_cmp_internal(rrtimeslice_t *ts1, rrtimeslice_t *ts2)
+rrtimeslice_seq_cmp_internal(rrtimeslice_t *ts1, rrtimeslice_t *ts2)
{
if ((! ts1) && (! ts2))
return 0;
"rrtimeslices with different typmods (yet)")
));
- if (ts1->seq == ts2->seq)
+ if (ts1->seq < ts2->seq)
+ return -1;
+ else if (ts1->seq == ts2->seq)
return 0;
-
- return timestamp_cmp_internal(ts1->tstamp, ts2->tstamp);
-} /* rrtimeslice_cmp_internal */
+ else
+ return 1;
+} /* rrtimeslice_seq_cmp_internal */
Datum
-rrtimeslice_eq(PG_FUNCTION_ARGS)
+rrtimeslice_seq_eq(PG_FUNCTION_ARGS)
{
rrtimeslice_t *ts1 = PG_GETARG_RRTIMESLICE_P(0);
rrtimeslice_t *ts2 = PG_GETARG_RRTIMESLICE_P(1);
- PG_RETURN_BOOL(rrtimeslice_cmp_internal(ts1, ts2) == 0);
-} /* rrtimeslice_eq */
+ PG_RETURN_BOOL(rrtimeslice_seq_cmp_internal(ts1, ts2) == 0);
+} /* rrtimeslice_seq_eq */
Datum
-rrtimeslice_ne(PG_FUNCTION_ARGS)
+rrtimeslice_seq_ne(PG_FUNCTION_ARGS)
{
rrtimeslice_t *ts1 = PG_GETARG_RRTIMESLICE_P(0);
rrtimeslice_t *ts2 = PG_GETARG_RRTIMESLICE_P(1);
- PG_RETURN_BOOL(rrtimeslice_cmp_internal(ts1, ts2) != 0);
-} /* rrtimeslice_ne */
+ PG_RETURN_BOOL(rrtimeslice_seq_cmp_internal(ts1, ts2) != 0);
+} /* rrtimeslice_seq_ne */
Datum
-rrtimeslice_lt(PG_FUNCTION_ARGS)
+rrtimeslice_seq_lt(PG_FUNCTION_ARGS)
{
rrtimeslice_t *ts1 = PG_GETARG_RRTIMESLICE_P(0);
rrtimeslice_t *ts2 = PG_GETARG_RRTIMESLICE_P(1);
- PG_RETURN_BOOL(rrtimeslice_cmp_internal(ts1, ts2) < 0);
-} /* rrtimeslice_lt */
+ PG_RETURN_BOOL(rrtimeslice_seq_cmp_internal(ts1, ts2) < 0);
+} /* rrtimeslice_seq_lt */
Datum
-rrtimeslice_le(PG_FUNCTION_ARGS)
+rrtimeslice_seq_le(PG_FUNCTION_ARGS)
{
rrtimeslice_t *ts1 = PG_GETARG_RRTIMESLICE_P(0);
rrtimeslice_t *ts2 = PG_GETARG_RRTIMESLICE_P(1);
- PG_RETURN_BOOL(rrtimeslice_cmp_internal(ts1, ts2) <= 0);
-} /* rrtimeslice_le */
+ PG_RETURN_BOOL(rrtimeslice_seq_cmp_internal(ts1, ts2) <= 0);
+} /* rrtimeslice_seq_le */
Datum
-rrtimeslice_gt(PG_FUNCTION_ARGS)
+rrtimeslice_seq_gt(PG_FUNCTION_ARGS)
{
rrtimeslice_t *ts1 = PG_GETARG_RRTIMESLICE_P(0);
rrtimeslice_t *ts2 = PG_GETARG_RRTIMESLICE_P(1);
- PG_RETURN_BOOL(rrtimeslice_cmp_internal(ts1, ts2) > 0);
-} /* rrtimeslice_gt */
+ PG_RETURN_BOOL(rrtimeslice_seq_cmp_internal(ts1, ts2) > 0);
+} /* rrtimeslice_seq_gt */
Datum
-rrtimeslice_ge(PG_FUNCTION_ARGS)
+rrtimeslice_seq_ge(PG_FUNCTION_ARGS)
{
rrtimeslice_t *ts1 = PG_GETARG_RRTIMESLICE_P(0);
rrtimeslice_t *ts2 = PG_GETARG_RRTIMESLICE_P(1);
- PG_RETURN_BOOL(rrtimeslice_cmp_internal(ts1, ts2) >= 0);
-} /* rrtimeslice_ge */
+ PG_RETURN_BOOL(rrtimeslice_seq_cmp_internal(ts1, ts2) >= 0);
+} /* rrtimeslice_seq_ge */
Datum
-rrtimeslice_cmp(PG_FUNCTION_ARGS)
+rrtimeslice_seq_cmp(PG_FUNCTION_ARGS)
{
rrtimeslice_t *ts1 = PG_GETARG_RRTIMESLICE_P(0);
rrtimeslice_t *ts2 = PG_GETARG_RRTIMESLICE_P(1);
- PG_RETURN_INT32(rrtimeslice_cmp_internal(ts1, ts2));
-} /* rrtimeslice_ge */
+ PG_RETURN_INT32(rrtimeslice_seq_cmp_internal(ts1, ts2));
+} /* rrtimeslice_seq_ge */
Datum
-rrtimeslice_hash(PG_FUNCTION_ARGS)
+rrtimeslice_seq_hash(PG_FUNCTION_ARGS)
{
rrtimeslice_t *ts = PG_GETARG_RRTIMESLICE_P(0);
return hash_uint32(ts->seq);
-} /* rrtimeslice_hash */
+} /* rrtimeslice_seq_hash */
/* vim: set tw=78 sw=4 ts=4 noexpandtab : */