#include <math.h>
#include "fmgr.h"
Go to the source code of this file.
Data Structures | |
struct | TimeTzADT |
Defines | |
#define | DATEVAL_NOBEGIN ((DateADT) (-0x7fffffff - 1)) |
#define | DATEVAL_NOEND ((DateADT) 0x7fffffff) |
#define | DATE_NOBEGIN(j) ((j) = DATEVAL_NOBEGIN) |
#define | DATE_IS_NOBEGIN(j) ((j) == DATEVAL_NOBEGIN) |
#define | DATE_NOEND(j) ((j) = DATEVAL_NOEND) |
#define | DATE_IS_NOEND(j) ((j) == DATEVAL_NOEND) |
#define | DATE_NOT_FINITE(j) (DATE_IS_NOBEGIN(j) || DATE_IS_NOEND(j)) |
#define | MAX_TIME_PRECISION 10 |
#define | TIME_PREC_INV 10000000000.0 |
#define | TIMEROUND(j) (rint(((double) (j)) * TIME_PREC_INV) / TIME_PREC_INV) |
#define | DatumGetDateADT(X) ((DateADT) DatumGetInt32(X)) |
#define | DatumGetTimeADT(X) ((TimeADT) DatumGetFloat8(X)) |
#define | DatumGetTimeTzADTP(X) ((TimeTzADT *) DatumGetPointer(X)) |
#define | DateADTGetDatum(X) Int32GetDatum(X) |
#define | TimeADTGetDatum(X) Float8GetDatum(X) |
#define | TimeTzADTPGetDatum(X) PointerGetDatum(X) |
#define | PG_GETARG_DATEADT(n) DatumGetDateADT(PG_GETARG_DATUM(n)) |
#define | PG_GETARG_TIMEADT(n) DatumGetTimeADT(PG_GETARG_DATUM(n)) |
#define | PG_GETARG_TIMETZADT_P(n) DatumGetTimeTzADTP(PG_GETARG_DATUM(n)) |
#define | PG_RETURN_DATEADT(x) return DateADTGetDatum(x) |
#define | PG_RETURN_TIMEADT(x) return TimeADTGetDatum(x) |
#define | PG_RETURN_TIMETZADT_P(x) return TimeTzADTPGetDatum(x) |
Typedefs | |
typedef int32 | DateADT |
typedef float8 | TimeADT |
Functions | |
double | date2timestamp_no_overflow (DateADT dateVal) |
Datum | date_in (PG_FUNCTION_ARGS) |
Datum | date_out (PG_FUNCTION_ARGS) |
Datum | date_recv (PG_FUNCTION_ARGS) |
Datum | date_send (PG_FUNCTION_ARGS) |
Datum | date_eq (PG_FUNCTION_ARGS) |
Datum | date_ne (PG_FUNCTION_ARGS) |
Datum | date_lt (PG_FUNCTION_ARGS) |
Datum | date_le (PG_FUNCTION_ARGS) |
Datum | date_gt (PG_FUNCTION_ARGS) |
Datum | date_ge (PG_FUNCTION_ARGS) |
Datum | date_cmp (PG_FUNCTION_ARGS) |
Datum | date_sortsupport (PG_FUNCTION_ARGS) |
Datum | date_finite (PG_FUNCTION_ARGS) |
Datum | date_larger (PG_FUNCTION_ARGS) |
Datum | date_smaller (PG_FUNCTION_ARGS) |
Datum | date_mi (PG_FUNCTION_ARGS) |
Datum | date_pli (PG_FUNCTION_ARGS) |
Datum | date_mii (PG_FUNCTION_ARGS) |
Datum | date_eq_timestamp (PG_FUNCTION_ARGS) |
Datum | date_ne_timestamp (PG_FUNCTION_ARGS) |
Datum | date_lt_timestamp (PG_FUNCTION_ARGS) |
Datum | date_le_timestamp (PG_FUNCTION_ARGS) |
Datum | date_gt_timestamp (PG_FUNCTION_ARGS) |
Datum | date_ge_timestamp (PG_FUNCTION_ARGS) |
Datum | date_cmp_timestamp (PG_FUNCTION_ARGS) |
Datum | date_eq_timestamptz (PG_FUNCTION_ARGS) |
Datum | date_ne_timestamptz (PG_FUNCTION_ARGS) |
Datum | date_lt_timestamptz (PG_FUNCTION_ARGS) |
Datum | date_le_timestamptz (PG_FUNCTION_ARGS) |
Datum | date_gt_timestamptz (PG_FUNCTION_ARGS) |
Datum | date_ge_timestamptz (PG_FUNCTION_ARGS) |
Datum | date_cmp_timestamptz (PG_FUNCTION_ARGS) |
Datum | timestamp_eq_date (PG_FUNCTION_ARGS) |
Datum | timestamp_ne_date (PG_FUNCTION_ARGS) |
Datum | timestamp_lt_date (PG_FUNCTION_ARGS) |
Datum | timestamp_le_date (PG_FUNCTION_ARGS) |
Datum | timestamp_gt_date (PG_FUNCTION_ARGS) |
Datum | timestamp_ge_date (PG_FUNCTION_ARGS) |
Datum | timestamp_cmp_date (PG_FUNCTION_ARGS) |
Datum | timestamptz_eq_date (PG_FUNCTION_ARGS) |
Datum | timestamptz_ne_date (PG_FUNCTION_ARGS) |
Datum | timestamptz_lt_date (PG_FUNCTION_ARGS) |
Datum | timestamptz_le_date (PG_FUNCTION_ARGS) |
Datum | timestamptz_gt_date (PG_FUNCTION_ARGS) |
Datum | timestamptz_ge_date (PG_FUNCTION_ARGS) |
Datum | timestamptz_cmp_date (PG_FUNCTION_ARGS) |
Datum | date_pl_interval (PG_FUNCTION_ARGS) |
Datum | date_mi_interval (PG_FUNCTION_ARGS) |
Datum | date_timestamp (PG_FUNCTION_ARGS) |
Datum | timestamp_date (PG_FUNCTION_ARGS) |
Datum | date_timestamptz (PG_FUNCTION_ARGS) |
Datum | timestamptz_date (PG_FUNCTION_ARGS) |
Datum | datetime_timestamp (PG_FUNCTION_ARGS) |
Datum | abstime_date (PG_FUNCTION_ARGS) |
Datum | time_in (PG_FUNCTION_ARGS) |
Datum | time_out (PG_FUNCTION_ARGS) |
Datum | time_recv (PG_FUNCTION_ARGS) |
Datum | time_send (PG_FUNCTION_ARGS) |
Datum | timetypmodin (PG_FUNCTION_ARGS) |
Datum | timetypmodout (PG_FUNCTION_ARGS) |
Datum | time_transform (PG_FUNCTION_ARGS) |
Datum | time_scale (PG_FUNCTION_ARGS) |
Datum | time_eq (PG_FUNCTION_ARGS) |
Datum | time_ne (PG_FUNCTION_ARGS) |
Datum | time_lt (PG_FUNCTION_ARGS) |
Datum | time_le (PG_FUNCTION_ARGS) |
Datum | time_gt (PG_FUNCTION_ARGS) |
Datum | time_ge (PG_FUNCTION_ARGS) |
Datum | time_cmp (PG_FUNCTION_ARGS) |
Datum | time_hash (PG_FUNCTION_ARGS) |
Datum | overlaps_time (PG_FUNCTION_ARGS) |
Datum | time_larger (PG_FUNCTION_ARGS) |
Datum | time_smaller (PG_FUNCTION_ARGS) |
Datum | time_mi_time (PG_FUNCTION_ARGS) |
Datum | timestamp_time (PG_FUNCTION_ARGS) |
Datum | timestamptz_time (PG_FUNCTION_ARGS) |
Datum | time_interval (PG_FUNCTION_ARGS) |
Datum | interval_time (PG_FUNCTION_ARGS) |
Datum | time_pl_interval (PG_FUNCTION_ARGS) |
Datum | time_mi_interval (PG_FUNCTION_ARGS) |
Datum | time_part (PG_FUNCTION_ARGS) |
Datum | timetz_in (PG_FUNCTION_ARGS) |
Datum | timetz_out (PG_FUNCTION_ARGS) |
Datum | timetz_recv (PG_FUNCTION_ARGS) |
Datum | timetz_send (PG_FUNCTION_ARGS) |
Datum | timetztypmodin (PG_FUNCTION_ARGS) |
Datum | timetztypmodout (PG_FUNCTION_ARGS) |
Datum | timetz_scale (PG_FUNCTION_ARGS) |
Datum | timetz_eq (PG_FUNCTION_ARGS) |
Datum | timetz_ne (PG_FUNCTION_ARGS) |
Datum | timetz_lt (PG_FUNCTION_ARGS) |
Datum | timetz_le (PG_FUNCTION_ARGS) |
Datum | timetz_gt (PG_FUNCTION_ARGS) |
Datum | timetz_ge (PG_FUNCTION_ARGS) |
Datum | timetz_cmp (PG_FUNCTION_ARGS) |
Datum | timetz_hash (PG_FUNCTION_ARGS) |
Datum | overlaps_timetz (PG_FUNCTION_ARGS) |
Datum | timetz_larger (PG_FUNCTION_ARGS) |
Datum | timetz_smaller (PG_FUNCTION_ARGS) |
Datum | timetz_time (PG_FUNCTION_ARGS) |
Datum | time_timetz (PG_FUNCTION_ARGS) |
Datum | timestamptz_timetz (PG_FUNCTION_ARGS) |
Datum | datetimetz_timestamptz (PG_FUNCTION_ARGS) |
Datum | timetz_part (PG_FUNCTION_ARGS) |
Datum | timetz_zone (PG_FUNCTION_ARGS) |
Datum | timetz_izone (PG_FUNCTION_ARGS) |
Datum | timetz_pl_interval (PG_FUNCTION_ARGS) |
Datum | timetz_mi_interval (PG_FUNCTION_ARGS) |
#define DATE_IS_NOBEGIN | ( | j | ) | ((j) == DATEVAL_NOBEGIN) |
Definition at line 45 of file date.h.
Referenced by date2timestamp(), date2timestamp_no_overflow(), date2timestamptz(), datetimetz_timestamptz(), and EncodeSpecialDate().
#define DATE_IS_NOEND | ( | j | ) | ((j) == DATEVAL_NOEND) |
Definition at line 47 of file date.h.
Referenced by date2timestamp(), date2timestamp_no_overflow(), date2timestamptz(), datetimetz_timestamptz(), and EncodeSpecialDate().
#define DATE_NOBEGIN | ( | j | ) | ((j) = DATEVAL_NOBEGIN) |
Definition at line 44 of file date.h.
Referenced by abstime_date(), date_in(), timestamp_date(), and timestamptz_date().
#define DATE_NOEND | ( | j | ) | ((j) = DATEVAL_NOEND) |
Definition at line 46 of file date.h.
Referenced by abstime_date(), date_in(), timestamp_date(), and timestamptz_date().
#define DATE_NOT_FINITE | ( | j | ) | (DATE_IS_NOBEGIN(j) || DATE_IS_NOEND(j)) |
Definition at line 48 of file date.h.
Referenced by date_finite(), date_mi(), date_mii(), date_out(), date_pli(), date_recv(), and map_sql_value_to_xml_value().
#define DateADTGetDatum | ( | X | ) | Int32GetDatum(X) |
Definition at line 79 of file date.h.
Referenced by gbt_date_penalty(), gbt_dateeq(), gbt_datege(), gbt_dategt(), gbt_datekey_cmp(), gbt_datele(), gbt_datelt(), gdb_date_dist(), and leftmostvalue_date().
#define DATEVAL_NOBEGIN ((DateADT) (-0x7fffffff - 1)) |
Definition at line 41 of file date.h.
Referenced by leftmostvalue_date().
#define DatumGetDateADT | ( | X | ) | ((DateADT) DatumGetInt32(X)) |
Definition at line 75 of file date.h.
Referenced by convert_timevalue_to_scalar(), date_fastcmp(), gbt_num_compress(), and map_sql_value_to_xml_value().
#define DatumGetTimeADT | ( | X | ) | ((TimeADT) DatumGetFloat8(X)) |
Definition at line 76 of file date.h.
Referenced by convert_timevalue_to_scalar(), and gbt_num_compress().
#define DatumGetTimeTzADTP | ( | X | ) | ((TimeTzADT *) DatumGetPointer(X)) |
Definition at line 77 of file date.h.
Referenced by convert_timevalue_to_scalar(), and gbt_timetz_compress().
#define MAX_TIME_PRECISION 10 |
Definition at line 69 of file date.h.
Referenced by AdjustTimeForTypmod(), anytime_typmodin(), EncodeTimeOnly(), and time_transform().
#define PG_GETARG_DATEADT | ( | n | ) | DatumGetDateADT(PG_GETARG_DATUM(n)) |
Definition at line 84 of file date.h.
Referenced by date_cmp(), date_cmp_timestamp(), date_cmp_timestamptz(), date_eq(), date_eq_timestamp(), date_eq_timestamptz(), date_finite(), date_ge(), date_ge_timestamp(), date_ge_timestamptz(), date_gt(), date_gt_timestamp(), date_gt_timestamptz(), date_larger(), date_le(), date_le_timestamp(), date_le_timestamptz(), date_lt(), date_lt_timestamp(), date_lt_timestamptz(), date_mi(), date_mi_interval(), date_mii(), date_ne(), date_ne_timestamp(), date_ne_timestamptz(), date_out(), date_pl_interval(), date_pli(), date_send(), date_smaller(), date_timestamp(), date_timestamptz(), datetime_timestamp(), datetimetz_timestamptz(), gbt_date_consistent(), gbt_date_distance(), timestamp_cmp_date(), timestamp_eq_date(), timestamp_ge_date(), timestamp_gt_date(), timestamp_le_date(), timestamp_lt_date(), timestamp_ne_date(), timestamptz_cmp_date(), timestamptz_eq_date(), timestamptz_ge_date(), timestamptz_gt_date(), timestamptz_le_date(), timestamptz_lt_date(), and timestamptz_ne_date().
#define PG_GETARG_TIMEADT | ( | n | ) | DatumGetTimeADT(PG_GETARG_DATUM(n)) |
Definition at line 85 of file date.h.
Referenced by datetime_timestamp(), gbt_time_consistent(), gbt_time_distance(), time_cmp(), time_eq(), time_ge(), time_gt(), time_interval(), time_larger(), time_le(), time_lt(), time_mi_interval(), time_mi_time(), time_ne(), time_out(), time_part(), time_pl_interval(), time_scale(), time_send(), time_smaller(), and time_timetz().
#define PG_GETARG_TIMETZADT_P | ( | n | ) | DatumGetTimeTzADTP(PG_GETARG_DATUM(n)) |
Definition at line 86 of file date.h.
Referenced by datetimetz_timestamptz(), gbt_timetz_consistent(), timetz_cmp(), timetz_eq(), timetz_ge(), timetz_gt(), timetz_hash(), timetz_izone(), timetz_larger(), timetz_le(), timetz_lt(), timetz_mi_interval(), timetz_ne(), timetz_out(), timetz_part(), timetz_pl_interval(), timetz_scale(), timetz_send(), timetz_smaller(), timetz_time(), and timetz_zone().
#define PG_RETURN_DATEADT | ( | x | ) | return DateADTGetDatum(x) |
Definition at line 88 of file date.h.
Referenced by abstime_date(), date_in(), date_larger(), date_mii(), date_pli(), date_recv(), date_smaller(), timestamp_date(), timestamptz_date(), and to_date().
#define PG_RETURN_TIMEADT | ( | x | ) | return TimeADTGetDatum(x) |
Definition at line 89 of file date.h.
Referenced by interval_time(), time_in(), time_larger(), time_mi_interval(), time_pl_interval(), time_recv(), time_scale(), time_smaller(), timestamp_time(), timestamptz_time(), and timetz_time().
#define PG_RETURN_TIMETZADT_P | ( | x | ) | return TimeTzADTPGetDatum(x) |
Definition at line 90 of file date.h.
Referenced by time_timetz(), timestamptz_timetz(), timetz_in(), timetz_izone(), timetz_larger(), timetz_mi_interval(), timetz_pl_interval(), timetz_recv(), timetz_scale(), timetz_smaller(), and timetz_zone().
#define TimeADTGetDatum | ( | X | ) | Float8GetDatum(X) |
Definition at line 80 of file date.h.
Referenced by leftmostvalue_time().
#define TIMEROUND | ( | j | ) | (rint(((double) (j)) * TIME_PREC_INV) / TIME_PREC_INV) |
Definition at line 73 of file date.h.
Referenced by time2tm(), and timetz2tm().
#define TimeTzADTPGetDatum | ( | X | ) | PointerGetDatum(X) |
Definition at line 81 of file date.h.
Referenced by leftmostvalue_timetz().
Datum abstime_date | ( | PG_FUNCTION_ARGS | ) |
Definition at line 995 of file date.c.
References abstime2tm(), date2j(), DATE_NOBEGIN, DATE_NOEND, ereport, errcode(), errmsg(), ERROR, INVALID_ABSTIME, NOEND_ABSTIME, NOSTART_ABSTIME, NULL, PG_GETARG_ABSOLUTETIME, PG_RETURN_DATEADT, tm, pg_tm::tm_mday, pg_tm::tm_mon, and pg_tm::tm_year.
{ AbsoluteTime abstime = PG_GETARG_ABSOLUTETIME(0); DateADT result; struct pg_tm tt, *tm = &tt; int tz; switch (abstime) { case INVALID_ABSTIME: ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot convert reserved abstime value to date"))); result = 0; /* keep compiler quiet */ break; case NOSTART_ABSTIME: DATE_NOBEGIN(result); break; case NOEND_ABSTIME: DATE_NOEND(result); break; default: abstime2tm(abstime, &tz, tm, NULL); result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE; break; } PG_RETURN_DATEADT(result); }
double date2timestamp_no_overflow | ( | DateADT | dateVal | ) |
Definition at line 497 of file date.c.
References DATE_IS_NOBEGIN, DATE_IS_NOEND, SECS_PER_DAY, and USECS_PER_DAY.
Referenced by convert_timevalue_to_scalar().
{ double result; if (DATE_IS_NOBEGIN(dateVal)) result = -DBL_MAX; else if (DATE_IS_NOEND(dateVal)) result = DBL_MAX; else { #ifdef HAVE_INT64_TIMESTAMP /* date is days since 2000, timestamp is microseconds since same... */ result = dateVal * (double) USECS_PER_DAY; #else /* date is days since 2000, timestamp is seconds since same... */ result = dateVal * (double) SECS_PER_DAY; #endif } return result; }
Datum date_cmp | ( | PG_FUNCTION_ARGS | ) |
Definition at line 312 of file date.c.
References PG_GETARG_DATEADT, and PG_RETURN_INT32.
Referenced by gbt_datekey_cmp().
{ DateADT dateVal1 = PG_GETARG_DATEADT(0); DateADT dateVal2 = PG_GETARG_DATEADT(1); if (dateVal1 < dateVal2) PG_RETURN_INT32(-1); else if (dateVal1 > dateVal2) PG_RETURN_INT32(1); PG_RETURN_INT32(0); }
Datum date_cmp_timestamp | ( | PG_FUNCTION_ARGS | ) |
Definition at line 597 of file date.c.
References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_INT32, and timestamp_cmp_internal().
{ DateADT dateVal = PG_GETARG_DATEADT(0); Timestamp dt2 = PG_GETARG_TIMESTAMP(1); Timestamp dt1; dt1 = date2timestamp(dateVal); PG_RETURN_INT32(timestamp_cmp_internal(dt1, dt2)); }
Datum date_cmp_timestamptz | ( | PG_FUNCTION_ARGS | ) |
Definition at line 681 of file date.c.
References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_INT32, and timestamptz_cmp_internal.
{ DateADT dateVal = PG_GETARG_DATEADT(0); TimestampTz dt2 = PG_GETARG_TIMESTAMPTZ(1); TimestampTz dt1; dt1 = date2timestamptz(dateVal); PG_RETURN_INT32(timestamptz_cmp_internal(dt1, dt2)); }
Datum date_eq | ( | PG_FUNCTION_ARGS | ) |
Definition at line 258 of file date.c.
References PG_GETARG_DATEADT, and PG_RETURN_BOOL.
Referenced by gbt_dateeq().
{ DateADT dateVal1 = PG_GETARG_DATEADT(0); DateADT dateVal2 = PG_GETARG_DATEADT(1); PG_RETURN_BOOL(dateVal1 == dateVal2); }
Datum date_eq_timestamp | ( | PG_FUNCTION_ARGS | ) |
Definition at line 525 of file date.c.
References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_BOOL, and timestamp_cmp_internal().
{ DateADT dateVal = PG_GETARG_DATEADT(0); Timestamp dt2 = PG_GETARG_TIMESTAMP(1); Timestamp dt1; dt1 = date2timestamp(dateVal); PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) == 0); }
Datum date_eq_timestamptz | ( | PG_FUNCTION_ARGS | ) |
Definition at line 609 of file date.c.
References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_BOOL, and timestamptz_cmp_internal.
{ DateADT dateVal = PG_GETARG_DATEADT(0); TimestampTz dt2 = PG_GETARG_TIMESTAMPTZ(1); TimestampTz dt1; dt1 = date2timestamptz(dateVal); PG_RETURN_BOOL(timestamptz_cmp_internal(dt1, dt2) == 0); }
Datum date_finite | ( | PG_FUNCTION_ARGS | ) |
Definition at line 347 of file date.c.
References DATE_NOT_FINITE, PG_GETARG_DATEADT, and PG_RETURN_BOOL.
{ DateADT date = PG_GETARG_DATEADT(0); PG_RETURN_BOOL(!DATE_NOT_FINITE(date)); }
Datum date_ge | ( | PG_FUNCTION_ARGS | ) |
Definition at line 303 of file date.c.
References PG_GETARG_DATEADT, and PG_RETURN_BOOL.
Referenced by gbt_datege().
{ DateADT dateVal1 = PG_GETARG_DATEADT(0); DateADT dateVal2 = PG_GETARG_DATEADT(1); PG_RETURN_BOOL(dateVal1 >= dateVal2); }
Datum date_ge_timestamp | ( | PG_FUNCTION_ARGS | ) |
Definition at line 585 of file date.c.
References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_BOOL, and timestamp_cmp_internal().
{ DateADT dateVal = PG_GETARG_DATEADT(0); Timestamp dt2 = PG_GETARG_TIMESTAMP(1); Timestamp dt1; dt1 = date2timestamp(dateVal); PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) >= 0); }
Datum date_ge_timestamptz | ( | PG_FUNCTION_ARGS | ) |
Definition at line 669 of file date.c.
References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_BOOL, and timestamptz_cmp_internal.
{ DateADT dateVal = PG_GETARG_DATEADT(0); TimestampTz dt2 = PG_GETARG_TIMESTAMPTZ(1); TimestampTz dt1; dt1 = date2timestamptz(dateVal); PG_RETURN_BOOL(timestamptz_cmp_internal(dt1, dt2) >= 0); }
Datum date_gt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 294 of file date.c.
References PG_GETARG_DATEADT, and PG_RETURN_BOOL.
Referenced by gbt_dategt().
{ DateADT dateVal1 = PG_GETARG_DATEADT(0); DateADT dateVal2 = PG_GETARG_DATEADT(1); PG_RETURN_BOOL(dateVal1 > dateVal2); }
Datum date_gt_timestamp | ( | PG_FUNCTION_ARGS | ) |
Definition at line 561 of file date.c.
References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_BOOL, and timestamp_cmp_internal().
{ DateADT dateVal = PG_GETARG_DATEADT(0); Timestamp dt2 = PG_GETARG_TIMESTAMP(1); Timestamp dt1; dt1 = date2timestamp(dateVal); PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) > 0); }
Datum date_gt_timestamptz | ( | PG_FUNCTION_ARGS | ) |
Definition at line 645 of file date.c.
References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_BOOL, and timestamptz_cmp_internal.
{ DateADT dateVal = PG_GETARG_DATEADT(0); TimestampTz dt2 = PG_GETARG_TIMESTAMPTZ(1); TimestampTz dt1; dt1 = date2timestamptz(dateVal); PG_RETURN_BOOL(timestamptz_cmp_internal(dt1, dt2) > 0); }
Datum date_in | ( | PG_FUNCTION_ARGS | ) |
Definition at line 114 of file date.c.
References date2j(), DATE_NOBEGIN, DATE_NOEND, DateTimeParseError(), DecodeDateTime(), DTERR_BAD_FORMAT, DTK_CURRENT, DTK_DATE, DTK_EARLY, DTK_EPOCH, DTK_LATE, ereport, errcode(), errmsg(), ERROR, GetCurrentDateTime(), GetEpochTime(), IS_VALID_JULIAN, MAXDATEFIELDS, MAXDATELEN, ParseDateTime(), PG_GETARG_CSTRING, PG_RETURN_DATEADT, tm, pg_tm::tm_mday, pg_tm::tm_mon, and pg_tm::tm_year.
{ char *str = PG_GETARG_CSTRING(0); DateADT date; fsec_t fsec; struct pg_tm tt, *tm = &tt; int tzp; int dtype; int nf; int dterr; char *field[MAXDATEFIELDS]; int ftype[MAXDATEFIELDS]; char workbuf[MAXDATELEN + 1]; dterr = ParseDateTime(str, workbuf, sizeof(workbuf), field, ftype, MAXDATEFIELDS, &nf); if (dterr == 0) dterr = DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tzp); if (dterr != 0) DateTimeParseError(dterr, str, "date"); switch (dtype) { case DTK_DATE: break; case DTK_CURRENT: ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("date/time value \"current\" is no longer supported"))); GetCurrentDateTime(tm); break; case DTK_EPOCH: GetEpochTime(tm); break; case DTK_LATE: DATE_NOEND(date); PG_RETURN_DATEADT(date); case DTK_EARLY: DATE_NOBEGIN(date); PG_RETURN_DATEADT(date); default: DateTimeParseError(DTERR_BAD_FORMAT, str, "date"); break; } if (!IS_VALID_JULIAN(tm->tm_year, tm->tm_mon, tm->tm_mday)) ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), errmsg("date out of range: \"%s\"", str))); date = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE; PG_RETURN_DATEADT(date); }
Datum date_larger | ( | PG_FUNCTION_ARGS | ) |
Definition at line 355 of file date.c.
References PG_GETARG_DATEADT, and PG_RETURN_DATEADT.
{ DateADT dateVal1 = PG_GETARG_DATEADT(0); DateADT dateVal2 = PG_GETARG_DATEADT(1); PG_RETURN_DATEADT((dateVal1 > dateVal2) ? dateVal1 : dateVal2); }
Datum date_le | ( | PG_FUNCTION_ARGS | ) |
Definition at line 285 of file date.c.
References PG_GETARG_DATEADT, and PG_RETURN_BOOL.
Referenced by gbt_datele().
{ DateADT dateVal1 = PG_GETARG_DATEADT(0); DateADT dateVal2 = PG_GETARG_DATEADT(1); PG_RETURN_BOOL(dateVal1 <= dateVal2); }
Datum date_le_timestamp | ( | PG_FUNCTION_ARGS | ) |
Definition at line 573 of file date.c.
References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_BOOL, and timestamp_cmp_internal().
{ DateADT dateVal = PG_GETARG_DATEADT(0); Timestamp dt2 = PG_GETARG_TIMESTAMP(1); Timestamp dt1; dt1 = date2timestamp(dateVal); PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) <= 0); }
Datum date_le_timestamptz | ( | PG_FUNCTION_ARGS | ) |
Definition at line 657 of file date.c.
References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_BOOL, and timestamptz_cmp_internal.
{ DateADT dateVal = PG_GETARG_DATEADT(0); TimestampTz dt2 = PG_GETARG_TIMESTAMPTZ(1); TimestampTz dt1; dt1 = date2timestamptz(dateVal); PG_RETURN_BOOL(timestamptz_cmp_internal(dt1, dt2) <= 0); }
Datum date_lt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 276 of file date.c.
References PG_GETARG_DATEADT, and PG_RETURN_BOOL.
Referenced by gbt_datelt().
{ DateADT dateVal1 = PG_GETARG_DATEADT(0); DateADT dateVal2 = PG_GETARG_DATEADT(1); PG_RETURN_BOOL(dateVal1 < dateVal2); }
Datum date_lt_timestamp | ( | PG_FUNCTION_ARGS | ) |
Definition at line 549 of file date.c.
References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_BOOL, and timestamp_cmp_internal().
{ DateADT dateVal = PG_GETARG_DATEADT(0); Timestamp dt2 = PG_GETARG_TIMESTAMP(1); Timestamp dt1; dt1 = date2timestamp(dateVal); PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) < 0); }
Datum date_lt_timestamptz | ( | PG_FUNCTION_ARGS | ) |
Definition at line 633 of file date.c.
References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_BOOL, and timestamptz_cmp_internal.
{ DateADT dateVal = PG_GETARG_DATEADT(0); TimestampTz dt2 = PG_GETARG_TIMESTAMPTZ(1); TimestampTz dt1; dt1 = date2timestamptz(dateVal); PG_RETURN_BOOL(timestamptz_cmp_internal(dt1, dt2) < 0); }
Datum date_mi | ( | PG_FUNCTION_ARGS | ) |
Definition at line 375 of file date.c.
References DATE_NOT_FINITE, ereport, errcode(), errmsg(), ERROR, PG_GETARG_DATEADT, and PG_RETURN_INT32.
Referenced by date_dist(), gbt_date_penalty(), and gdb_date_dist().
{ DateADT dateVal1 = PG_GETARG_DATEADT(0); DateADT dateVal2 = PG_GETARG_DATEADT(1); if (DATE_NOT_FINITE(dateVal1) || DATE_NOT_FINITE(dateVal2)) ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), errmsg("cannot subtract infinite dates"))); PG_RETURN_INT32((int32) (dateVal1 - dateVal2)); }
Datum date_mi_interval | ( | PG_FUNCTION_ARGS | ) |
Definition at line 888 of file date.c.
References date2timestamp(), DirectFunctionCall2, PG_GETARG_DATEADT, PG_GETARG_INTERVAL_P, PointerGetDatum, timestamp_mi_interval(), and TimestampGetDatum.
{ DateADT dateVal = PG_GETARG_DATEADT(0); Interval *span = PG_GETARG_INTERVAL_P(1); Timestamp dateStamp; dateStamp = date2timestamp(dateVal); return DirectFunctionCall2(timestamp_mi_interval, TimestampGetDatum(dateStamp), PointerGetDatum(span)); }
Datum date_mii | ( | PG_FUNCTION_ARGS | ) |
Definition at line 406 of file date.c.
References DATE_NOT_FINITE, days, PG_GETARG_DATEADT, PG_GETARG_INT32, and PG_RETURN_DATEADT.
{ DateADT dateVal = PG_GETARG_DATEADT(0); int32 days = PG_GETARG_INT32(1); if (DATE_NOT_FINITE(dateVal)) days = 0; /* can't change infinity */ PG_RETURN_DATEADT(dateVal - days); }
Datum date_ne | ( | PG_FUNCTION_ARGS | ) |
Definition at line 267 of file date.c.
References PG_GETARG_DATEADT, and PG_RETURN_BOOL.
{ DateADT dateVal1 = PG_GETARG_DATEADT(0); DateADT dateVal2 = PG_GETARG_DATEADT(1); PG_RETURN_BOOL(dateVal1 != dateVal2); }
Datum date_ne_timestamp | ( | PG_FUNCTION_ARGS | ) |
Definition at line 537 of file date.c.
References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_BOOL, and timestamp_cmp_internal().
{ DateADT dateVal = PG_GETARG_DATEADT(0); Timestamp dt2 = PG_GETARG_TIMESTAMP(1); Timestamp dt1; dt1 = date2timestamp(dateVal); PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) != 0); }
Datum date_ne_timestamptz | ( | PG_FUNCTION_ARGS | ) |
Definition at line 621 of file date.c.
References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_BOOL, and timestamptz_cmp_internal.
{ DateADT dateVal = PG_GETARG_DATEADT(0); TimestampTz dt2 = PG_GETARG_TIMESTAMPTZ(1); TimestampTz dt1; dt1 = date2timestamptz(dateVal); PG_RETURN_BOOL(timestamptz_cmp_internal(dt1, dt2) != 0); }
Datum date_out | ( | PG_FUNCTION_ARGS | ) |
Definition at line 180 of file date.c.
References buf, DATE_NOT_FINITE, DateStyle, EncodeDateOnly(), EncodeSpecialDate(), j2date(), MAXDATELEN, PG_GETARG_DATEADT, PG_RETURN_CSTRING, POSTGRES_EPOCH_JDATE, pstrdup(), tm, pg_tm::tm_mday, pg_tm::tm_mon, and pg_tm::tm_year.
{ DateADT date = PG_GETARG_DATEADT(0); char *result; struct pg_tm tt, *tm = &tt; char buf[MAXDATELEN + 1]; if (DATE_NOT_FINITE(date)) EncodeSpecialDate(date, buf); else { j2date(date + POSTGRES_EPOCH_JDATE, &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday)); EncodeDateOnly(tm, DateStyle, buf); } result = pstrdup(buf); PG_RETURN_CSTRING(result); }
Datum date_pl_interval | ( | PG_FUNCTION_ARGS | ) |
Definition at line 868 of file date.c.
References date2timestamp(), DirectFunctionCall2, PG_GETARG_DATEADT, PG_GETARG_INTERVAL_P, PointerGetDatum, timestamp_pl_interval(), and TimestampGetDatum.
{ DateADT dateVal = PG_GETARG_DATEADT(0); Interval *span = PG_GETARG_INTERVAL_P(1); Timestamp dateStamp; dateStamp = date2timestamp(dateVal); return DirectFunctionCall2(timestamp_pl_interval, TimestampGetDatum(dateStamp), PointerGetDatum(span)); }
Datum date_pli | ( | PG_FUNCTION_ARGS | ) |
Definition at line 392 of file date.c.
References DATE_NOT_FINITE, days, PG_GETARG_DATEADT, PG_GETARG_INT32, and PG_RETURN_DATEADT.
Referenced by daterange_canonical().
{ DateADT dateVal = PG_GETARG_DATEADT(0); int32 days = PG_GETARG_INT32(1); if (DATE_NOT_FINITE(dateVal)) days = 0; /* can't change infinity */ PG_RETURN_DATEADT(dateVal + days); }
Datum date_recv | ( | PG_FUNCTION_ARGS | ) |
Definition at line 205 of file date.c.
References buf, DATE_NOT_FINITE, ereport, errcode(), errmsg(), ERROR, JULIAN_MAX, PG_GETARG_POINTER, PG_RETURN_DATEADT, POSTGRES_EPOCH_JDATE, and pq_getmsgint().
{ StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); DateADT result; result = (DateADT) pq_getmsgint(buf, sizeof(DateADT)); /* Limit to the same range that date_in() accepts. */ if (DATE_NOT_FINITE(result)) /* ok */ ; else if (result < -POSTGRES_EPOCH_JDATE || result >= JULIAN_MAX - POSTGRES_EPOCH_JDATE) ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), errmsg("date out of range"))); PG_RETURN_DATEADT(result); }
Datum date_send | ( | PG_FUNCTION_ARGS | ) |
Definition at line 228 of file date.c.
References buf, PG_GETARG_DATEADT, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint().
{ DateADT date = PG_GETARG_DATEADT(0); StringInfoData buf; pq_begintypsend(&buf); pq_sendint(&buf, date, sizeof(date)); PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); }
Datum date_smaller | ( | PG_FUNCTION_ARGS | ) |
Definition at line 364 of file date.c.
References PG_GETARG_DATEADT, and PG_RETURN_DATEADT.
{ DateADT dateVal1 = PG_GETARG_DATEADT(0); DateADT dateVal2 = PG_GETARG_DATEADT(1); PG_RETURN_DATEADT((dateVal1 < dateVal2) ? dateVal1 : dateVal2); }
Datum date_sortsupport | ( | PG_FUNCTION_ARGS | ) |
Definition at line 338 of file date.c.
References SortSupportData::comparator, PG_GETARG_POINTER, and PG_RETURN_VOID.
{ SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0); ssup->comparator = date_fastcmp; PG_RETURN_VOID(); }
Datum date_timestamp | ( | PG_FUNCTION_ARGS | ) |
Definition at line 905 of file date.c.
References date2timestamp(), PG_GETARG_DATEADT, and PG_RETURN_TIMESTAMP.
{ DateADT dateVal = PG_GETARG_DATEADT(0); Timestamp result; result = date2timestamp(dateVal); PG_RETURN_TIMESTAMP(result); }
Datum date_timestamptz | ( | PG_FUNCTION_ARGS | ) |
Definition at line 949 of file date.c.
References date2timestamptz(), PG_GETARG_DATEADT, and PG_RETURN_TIMESTAMP.
{ DateADT dateVal = PG_GETARG_DATEADT(0); TimestampTz result; result = date2timestamptz(dateVal); PG_RETURN_TIMESTAMP(result); }
Datum datetime_timestamp | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1606 of file date.c.
References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMEADT, PG_RETURN_TIMESTAMP, and TIMESTAMP_NOT_FINITE.
{ DateADT date = PG_GETARG_DATEADT(0); TimeADT time = PG_GETARG_TIMEADT(1); Timestamp result; result = date2timestamp(date); if (!TIMESTAMP_NOT_FINITE(result)) result += time; PG_RETURN_TIMESTAMP(result); }
Datum datetimetz_timestamptz | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2474 of file date.c.
References DATE_IS_NOBEGIN, DATE_IS_NOEND, PG_GETARG_DATEADT, PG_GETARG_TIMETZADT_P, PG_RETURN_TIMESTAMP, SECS_PER_DAY, TimeTzADT::time, TIMESTAMP_NOBEGIN, TIMESTAMP_NOEND, USECS_PER_DAY, and TimeTzADT::zone.
{ DateADT date = PG_GETARG_DATEADT(0); TimeTzADT *time = PG_GETARG_TIMETZADT_P(1); TimestampTz result; if (DATE_IS_NOBEGIN(date)) TIMESTAMP_NOBEGIN(result); else if (DATE_IS_NOEND(date)) TIMESTAMP_NOEND(result); else { #ifdef HAVE_INT64_TIMESTAMP result = date * USECS_PER_DAY + time->time + time->zone * USECS_PER_SEC; #else result = date * (double) SECS_PER_DAY + time->time + time->zone; #endif } PG_RETURN_TIMESTAMP(result); }
Datum interval_time | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1646 of file date.c.
References days, PG_GETARG_INTERVAL_P, PG_RETURN_TIMEADT, SECS_PER_DAY, Interval::time, and USECS_PER_DAY.
{ Interval *span = PG_GETARG_INTERVAL_P(0); TimeADT result; #ifdef HAVE_INT64_TIMESTAMP int64 days; result = span->time; if (result >= USECS_PER_DAY) { days = result / USECS_PER_DAY; result -= days * USECS_PER_DAY; } else if (result < 0) { days = (-result + USECS_PER_DAY - 1) / USECS_PER_DAY; result += days * USECS_PER_DAY; } #else result = span->time; if (result >= (double) SECS_PER_DAY || result < 0) result -= floor(result / (double) SECS_PER_DAY) * (double) SECS_PER_DAY; #endif PG_RETURN_TIMEADT(result); }
Datum overlaps_time | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1413 of file date.c.
References PG_ARGISNULL, PG_GETARG_DATUM, PG_RETURN_BOOL, PG_RETURN_NULL, TIMEADT_GT, and TIMEADT_LT.
{ /* * The arguments are TimeADT, but we leave them as generic Datums to avoid * dereferencing nulls (TimeADT is pass-by-reference!) */ Datum ts1 = PG_GETARG_DATUM(0); Datum te1 = PG_GETARG_DATUM(1); Datum ts2 = PG_GETARG_DATUM(2); Datum te2 = PG_GETARG_DATUM(3); bool ts1IsNull = PG_ARGISNULL(0); bool te1IsNull = PG_ARGISNULL(1); bool ts2IsNull = PG_ARGISNULL(2); bool te2IsNull = PG_ARGISNULL(3); #define TIMEADT_GT(t1,t2) \ (DatumGetTimeADT(t1) > DatumGetTimeADT(t2)) #define TIMEADT_LT(t1,t2) \ (DatumGetTimeADT(t1) < DatumGetTimeADT(t2)) /* * If both endpoints of interval 1 are null, the result is null (unknown). * If just one endpoint is null, take ts1 as the non-null one. Otherwise, * take ts1 as the lesser endpoint. */ if (ts1IsNull) { if (te1IsNull) PG_RETURN_NULL(); /* swap null for non-null */ ts1 = te1; te1IsNull = true; } else if (!te1IsNull) { if (TIMEADT_GT(ts1, te1)) { Datum tt = ts1; ts1 = te1; te1 = tt; } } /* Likewise for interval 2. */ if (ts2IsNull) { if (te2IsNull) PG_RETURN_NULL(); /* swap null for non-null */ ts2 = te2; te2IsNull = true; } else if (!te2IsNull) { if (TIMEADT_GT(ts2, te2)) { Datum tt = ts2; ts2 = te2; te2 = tt; } } /* * At this point neither ts1 nor ts2 is null, so we can consider three * cases: ts1 > ts2, ts1 < ts2, ts1 = ts2 */ if (TIMEADT_GT(ts1, ts2)) { /* * This case is ts1 < te2 OR te1 < te2, which may look redundant but * in the presence of nulls it's not quite completely so. */ if (te2IsNull) PG_RETURN_NULL(); if (TIMEADT_LT(ts1, te2)) PG_RETURN_BOOL(true); if (te1IsNull) PG_RETURN_NULL(); /* * If te1 is not null then we had ts1 <= te1 above, and we just found * ts1 >= te2, hence te1 >= te2. */ PG_RETURN_BOOL(false); } else if (TIMEADT_LT(ts1, ts2)) { /* This case is ts2 < te1 OR te2 < te1 */ if (te1IsNull) PG_RETURN_NULL(); if (TIMEADT_LT(ts2, te1)) PG_RETURN_BOOL(true); if (te2IsNull) PG_RETURN_NULL(); /* * If te2 is not null then we had ts2 <= te2 above, and we just found * ts2 >= te1, hence te2 >= te1. */ PG_RETURN_BOOL(false); } else { /* * For ts1 = ts2 the spec says te1 <> te2 OR te1 = te2, which is a * rather silly way of saying "true if both are nonnull, else null". */ if (te1IsNull || te2IsNull) PG_RETURN_NULL(); PG_RETURN_BOOL(true); } #undef TIMEADT_GT #undef TIMEADT_LT }
Datum overlaps_timetz | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2283 of file date.c.
References PG_ARGISNULL, PG_GETARG_DATUM, PG_RETURN_BOOL, PG_RETURN_NULL, TIMETZ_GT, and TIMETZ_LT.
{ /* * The arguments are TimeTzADT *, but we leave them as generic Datums for * convenience of notation --- and to avoid dereferencing nulls. */ Datum ts1 = PG_GETARG_DATUM(0); Datum te1 = PG_GETARG_DATUM(1); Datum ts2 = PG_GETARG_DATUM(2); Datum te2 = PG_GETARG_DATUM(3); bool ts1IsNull = PG_ARGISNULL(0); bool te1IsNull = PG_ARGISNULL(1); bool ts2IsNull = PG_ARGISNULL(2); bool te2IsNull = PG_ARGISNULL(3); #define TIMETZ_GT(t1,t2) \ DatumGetBool(DirectFunctionCall2(timetz_gt,t1,t2)) #define TIMETZ_LT(t1,t2) \ DatumGetBool(DirectFunctionCall2(timetz_lt,t1,t2)) /* * If both endpoints of interval 1 are null, the result is null (unknown). * If just one endpoint is null, take ts1 as the non-null one. Otherwise, * take ts1 as the lesser endpoint. */ if (ts1IsNull) { if (te1IsNull) PG_RETURN_NULL(); /* swap null for non-null */ ts1 = te1; te1IsNull = true; } else if (!te1IsNull) { if (TIMETZ_GT(ts1, te1)) { Datum tt = ts1; ts1 = te1; te1 = tt; } } /* Likewise for interval 2. */ if (ts2IsNull) { if (te2IsNull) PG_RETURN_NULL(); /* swap null for non-null */ ts2 = te2; te2IsNull = true; } else if (!te2IsNull) { if (TIMETZ_GT(ts2, te2)) { Datum tt = ts2; ts2 = te2; te2 = tt; } } /* * At this point neither ts1 nor ts2 is null, so we can consider three * cases: ts1 > ts2, ts1 < ts2, ts1 = ts2 */ if (TIMETZ_GT(ts1, ts2)) { /* * This case is ts1 < te2 OR te1 < te2, which may look redundant but * in the presence of nulls it's not quite completely so. */ if (te2IsNull) PG_RETURN_NULL(); if (TIMETZ_LT(ts1, te2)) PG_RETURN_BOOL(true); if (te1IsNull) PG_RETURN_NULL(); /* * If te1 is not null then we had ts1 <= te1 above, and we just found * ts1 >= te2, hence te1 >= te2. */ PG_RETURN_BOOL(false); } else if (TIMETZ_LT(ts1, ts2)) { /* This case is ts2 < te1 OR te2 < te1 */ if (te1IsNull) PG_RETURN_NULL(); if (TIMETZ_LT(ts2, te1)) PG_RETURN_BOOL(true); if (te2IsNull) PG_RETURN_NULL(); /* * If te2 is not null then we had ts2 <= te2 above, and we just found * ts2 >= te1, hence te2 >= te1. */ PG_RETURN_BOOL(false); } else { /* * For ts1 = ts2 the spec says te1 <> te2 OR te1 = te2, which is a * rather silly way of saying "true if both are nonnull, else null". */ if (te1IsNull || te2IsNull) PG_RETURN_NULL(); PG_RETURN_BOOL(true); } #undef TIMETZ_GT #undef TIMETZ_LT }
Datum time_cmp | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1365 of file date.c.
References PG_GETARG_TIMEADT, and PG_RETURN_INT32.
Referenced by gbt_timekey_cmp().
{ TimeADT time1 = PG_GETARG_TIMEADT(0); TimeADT time2 = PG_GETARG_TIMEADT(1); if (time1 < time2) PG_RETURN_INT32(-1); if (time1 > time2) PG_RETURN_INT32(1); PG_RETURN_INT32(0); }
Datum time_eq | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1311 of file date.c.
References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.
Referenced by gbt_timeeq().
{ TimeADT time1 = PG_GETARG_TIMEADT(0); TimeADT time2 = PG_GETARG_TIMEADT(1); PG_RETURN_BOOL(time1 == time2); }
Datum time_ge | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1356 of file date.c.
References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.
Referenced by gbt_timege().
{ TimeADT time1 = PG_GETARG_TIMEADT(0); TimeADT time2 = PG_GETARG_TIMEADT(1); PG_RETURN_BOOL(time1 >= time2); }
Datum time_gt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1347 of file date.c.
References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.
Referenced by gbt_timegt().
{ TimeADT time1 = PG_GETARG_TIMEADT(0); TimeADT time2 = PG_GETARG_TIMEADT(1); PG_RETURN_BOOL(time1 > time2); }
Datum time_hash | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1378 of file date.c.
References hashfloat8(), and hashint8().
{ /* We can use either hashint8 or hashfloat8 directly */ #ifdef HAVE_INT64_TIMESTAMP return hashint8(fcinfo); #else return hashfloat8(fcinfo); #endif }
Datum time_in | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1035 of file date.c.
References AdjustTimeForTypmod(), DateTimeParseError(), DecodeTimeOnly(), MAXDATEFIELDS, MAXDATELEN, ParseDateTime(), PG_GETARG_CSTRING, PG_GETARG_INT32, PG_GETARG_OID, PG_RETURN_TIMEADT, tm, and tm2time().
{ char *str = PG_GETARG_CSTRING(0); #ifdef NOT_USED Oid typelem = PG_GETARG_OID(1); #endif int32 typmod = PG_GETARG_INT32(2); TimeADT result; fsec_t fsec; struct pg_tm tt, *tm = &tt; int tz; int nf; int dterr; char workbuf[MAXDATELEN + 1]; char *field[MAXDATEFIELDS]; int dtype; int ftype[MAXDATEFIELDS]; dterr = ParseDateTime(str, workbuf, sizeof(workbuf), field, ftype, MAXDATEFIELDS, &nf); if (dterr == 0) dterr = DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, &tz); if (dterr != 0) DateTimeParseError(dterr, str, "time"); tm2time(tm, fsec, &result); AdjustTimeForTypmod(&result, typmod); PG_RETURN_TIMEADT(result); }
Datum time_interval | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1623 of file date.c.
References Interval::day, Interval::month, palloc(), PG_GETARG_TIMEADT, PG_RETURN_INTERVAL_P, and Interval::time.
{ TimeADT time = PG_GETARG_TIMEADT(0); Interval *result; result = (Interval *) palloc(sizeof(Interval)); result->time = time; result->day = 0; result->month = 0; PG_RETURN_INTERVAL_P(result); }
Datum time_larger | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1389 of file date.c.
References PG_GETARG_TIMEADT, and PG_RETURN_TIMEADT.
{ TimeADT time1 = PG_GETARG_TIMEADT(0); TimeADT time2 = PG_GETARG_TIMEADT(1); PG_RETURN_TIMEADT((time1 > time2) ? time1 : time2); }
Datum time_le | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1338 of file date.c.
References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.
Referenced by gbt_timele().
{ TimeADT time1 = PG_GETARG_TIMEADT(0); TimeADT time2 = PG_GETARG_TIMEADT(1); PG_RETURN_BOOL(time1 <= time2); }
Datum time_lt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1329 of file date.c.
References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.
Referenced by gbt_timelt().
{ TimeADT time1 = PG_GETARG_TIMEADT(0); TimeADT time2 = PG_GETARG_TIMEADT(1); PG_RETURN_BOOL(time1 < time2); }
Datum time_mi_interval | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1724 of file date.c.
References INT64CONST, PG_GETARG_INTERVAL_P, PG_GETARG_TIMEADT, PG_RETURN_TIMEADT, SECS_PER_DAY, Interval::time, TMODULO, and USECS_PER_DAY.
{ TimeADT time = PG_GETARG_TIMEADT(0); Interval *span = PG_GETARG_INTERVAL_P(1); TimeADT result; #ifdef HAVE_INT64_TIMESTAMP result = time - span->time; result -= result / USECS_PER_DAY * USECS_PER_DAY; if (result < INT64CONST(0)) result += USECS_PER_DAY; #else TimeADT time1; result = time - span->time; TMODULO(result, time1, (double) SECS_PER_DAY); if (result < 0) result += SECS_PER_DAY; #endif PG_RETURN_TIMEADT(result); }
Datum time_mi_time | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1678 of file date.c.
References Interval::day, Interval::month, palloc(), PG_GETARG_TIMEADT, PG_RETURN_INTERVAL_P, and Interval::time.
Referenced by gbt_time_dist(), gbt_time_penalty(), and time_dist().
{ TimeADT time1 = PG_GETARG_TIMEADT(0); TimeADT time2 = PG_GETARG_TIMEADT(1); Interval *result; result = (Interval *) palloc(sizeof(Interval)); result->month = 0; result->day = 0; result->time = time1 - time2; PG_RETURN_INTERVAL_P(result); }
Datum time_ne | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1320 of file date.c.
References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.
{ TimeADT time1 = PG_GETARG_TIMEADT(0); TimeADT time2 = PG_GETARG_TIMEADT(1); PG_RETURN_BOOL(time1 != time2); }
Datum time_out | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1123 of file date.c.
References buf, DateStyle, EncodeTimeOnly(), MAXDATELEN, PG_GETARG_TIMEADT, PG_RETURN_CSTRING, pstrdup(), time2tm(), and tm.
{ TimeADT time = PG_GETARG_TIMEADT(0); char *result; struct pg_tm tt, *tm = &tt; fsec_t fsec; char buf[MAXDATELEN + 1]; time2tm(time, tm, &fsec); EncodeTimeOnly(tm, fsec, false, 0, DateStyle, buf); result = pstrdup(buf); PG_RETURN_CSTRING(result); }
Datum time_part | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1752 of file date.c.
References DecodeSpecial(), DecodeUnits(), downcase_truncate_identifier(), DTK_CENTURY, DTK_DAY, DTK_DECADE, DTK_EPOCH, DTK_HOUR, DTK_ISOYEAR, DTK_MICROSEC, DTK_MILLENNIUM, DTK_MILLISEC, DTK_MINUTE, DTK_MONTH, DTK_QUARTER, DTK_SECOND, DTK_TZ, DTK_TZ_HOUR, DTK_TZ_MINUTE, DTK_YEAR, ereport, errcode(), errmsg(), ERROR, PG_GETARG_TEXT_PP, PG_GETARG_TIMEADT, PG_RETURN_FLOAT8, RESERV, time2tm(), tm, pg_tm::tm_hour, pg_tm::tm_min, pg_tm::tm_sec, UNITS, UNKNOWN_FIELD, val, VARDATA_ANY, and VARSIZE_ANY_EXHDR.
{ text *units = PG_GETARG_TEXT_PP(0); TimeADT time = PG_GETARG_TIMEADT(1); float8 result; int type, val; char *lowunits; lowunits = downcase_truncate_identifier(VARDATA_ANY(units), VARSIZE_ANY_EXHDR(units), false); type = DecodeUnits(0, lowunits, &val); if (type == UNKNOWN_FIELD) type = DecodeSpecial(0, lowunits, &val); if (type == UNITS) { fsec_t fsec; struct pg_tm tt, *tm = &tt; time2tm(time, tm, &fsec); switch (val) { case DTK_MICROSEC: #ifdef HAVE_INT64_TIMESTAMP result = tm->tm_sec * 1000000.0 + fsec; #else result = (tm->tm_sec + fsec) * 1000000; #endif break; case DTK_MILLISEC: #ifdef HAVE_INT64_TIMESTAMP result = tm->tm_sec * 1000.0 + fsec / 1000.0; #else result = (tm->tm_sec + fsec) * 1000; #endif break; case DTK_SECOND: #ifdef HAVE_INT64_TIMESTAMP result = tm->tm_sec + fsec / 1000000.0; #else result = tm->tm_sec + fsec; #endif break; case DTK_MINUTE: result = tm->tm_min; break; case DTK_HOUR: result = tm->tm_hour; break; case DTK_TZ: case DTK_TZ_MINUTE: case DTK_TZ_HOUR: case DTK_DAY: case DTK_MONTH: case DTK_QUARTER: case DTK_YEAR: case DTK_DECADE: case DTK_CENTURY: case DTK_MILLENNIUM: case DTK_ISOYEAR: default: ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("\"time\" units \"%s\" not recognized", lowunits))); result = 0; } } else if (type == RESERV && val == DTK_EPOCH) { #ifdef HAVE_INT64_TIMESTAMP result = time / 1000000.0; #else result = time; #endif } else { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("\"time\" units \"%s\" not recognized", lowunits))); result = 0; } PG_RETURN_FLOAT8(result); }
Datum time_pl_interval | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1697 of file date.c.
References INT64CONST, PG_GETARG_INTERVAL_P, PG_GETARG_TIMEADT, PG_RETURN_TIMEADT, SECS_PER_DAY, Interval::time, TMODULO, and USECS_PER_DAY.
{ TimeADT time = PG_GETARG_TIMEADT(0); Interval *span = PG_GETARG_INTERVAL_P(1); TimeADT result; #ifdef HAVE_INT64_TIMESTAMP result = time + span->time; result -= result / USECS_PER_DAY * USECS_PER_DAY; if (result < INT64CONST(0)) result += USECS_PER_DAY; #else TimeADT time1; result = time + span->time; TMODULO(result, time1, (double) SECS_PER_DAY); if (result < 0) result += SECS_PER_DAY; #endif PG_RETURN_TIMEADT(result); }
Datum time_recv | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1146 of file date.c.
References AdjustTimeForTypmod(), buf, ereport, errcode(), errmsg(), ERROR, INT64CONST, PG_GETARG_INT32, PG_GETARG_OID, PG_GETARG_POINTER, PG_RETURN_TIMEADT, pq_getmsgfloat8(), pq_getmsgint64(), SECS_PER_DAY, and USECS_PER_DAY.
{ StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); #ifdef NOT_USED Oid typelem = PG_GETARG_OID(1); #endif int32 typmod = PG_GETARG_INT32(2); TimeADT result; #ifdef HAVE_INT64_TIMESTAMP result = pq_getmsgint64(buf); if (result < INT64CONST(0) || result > USECS_PER_DAY) ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), errmsg("time out of range"))); #else result = pq_getmsgfloat8(buf); if (result < 0 || result > (double) SECS_PER_DAY) ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), errmsg("time out of range"))); #endif AdjustTimeForTypmod(&result, typmod); PG_RETURN_TIMEADT(result); }
Datum time_scale | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1228 of file date.c.
References AdjustTimeForTypmod(), PG_GETARG_INT32, PG_GETARG_TIMEADT, and PG_RETURN_TIMEADT.
{ TimeADT time = PG_GETARG_TIMEADT(0); int32 typmod = PG_GETARG_INT32(1); TimeADT result; result = time; AdjustTimeForTypmod(&result, typmod); PG_RETURN_TIMEADT(result); }
Datum time_send | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1181 of file date.c.
References buf, PG_GETARG_TIMEADT, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), pq_sendfloat8(), and pq_sendint64().
{ TimeADT time = PG_GETARG_TIMEADT(0); StringInfoData buf; pq_begintypsend(&buf); #ifdef HAVE_INT64_TIMESTAMP pq_sendint64(&buf, time); #else pq_sendfloat8(&buf, time); #endif PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); }
Datum time_smaller | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1398 of file date.c.
References PG_GETARG_TIMEADT, and PG_RETURN_TIMEADT.
{ TimeADT time1 = PG_GETARG_TIMEADT(0); TimeADT time2 = PG_GETARG_TIMEADT(1); PG_RETURN_TIMEADT((time1 < time2) ? time1 : time2); }
Datum time_timetz | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2416 of file date.c.
References DetermineTimeZoneOffset(), GetCurrentDateTime(), palloc(), PG_GETARG_TIMEADT, PG_RETURN_TIMETZADT_P, session_timezone, TimeTzADT::time, time2tm(), tm, and TimeTzADT::zone.
{ TimeADT time = PG_GETARG_TIMEADT(0); TimeTzADT *result; struct pg_tm tt, *tm = &tt; fsec_t fsec; int tz; GetCurrentDateTime(tm); time2tm(time, tm, &fsec); tz = DetermineTimeZoneOffset(tm, session_timezone); result = (TimeTzADT *) palloc(sizeof(TimeTzADT)); result->time = time; result->zone = tz; PG_RETURN_TIMETZADT_P(result); }
Datum time_transform | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1217 of file date.c.
References MAX_TIME_PRECISION, PG_GETARG_POINTER, PG_RETURN_POINTER, and TemporalTransform().
{ PG_RETURN_POINTER(TemporalTransform(MAX_TIME_PRECISION, (Node *) PG_GETARG_POINTER(0))); }
Datum timestamp_cmp_date | ( | PG_FUNCTION_ARGS | ) |
Definition at line 765 of file date.c.
References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_INT32, and timestamp_cmp_internal().
{ Timestamp dt1 = PG_GETARG_TIMESTAMP(0); DateADT dateVal = PG_GETARG_DATEADT(1); Timestamp dt2; dt2 = date2timestamp(dateVal); PG_RETURN_INT32(timestamp_cmp_internal(dt1, dt2)); }
Datum timestamp_date | ( | PG_FUNCTION_ARGS | ) |
Definition at line 919 of file date.c.
References date2j(), DATE_NOBEGIN, DATE_NOEND, ereport, errcode(), errmsg(), ERROR, NULL, PG_GETARG_TIMESTAMP, PG_RETURN_DATEADT, timestamp2tm(), TIMESTAMP_IS_NOBEGIN, TIMESTAMP_IS_NOEND, tm, pg_tm::tm_mday, pg_tm::tm_mon, and pg_tm::tm_year.
{ Timestamp timestamp = PG_GETARG_TIMESTAMP(0); DateADT result; struct pg_tm tt, *tm = &tt; fsec_t fsec; if (TIMESTAMP_IS_NOBEGIN(timestamp)) DATE_NOBEGIN(result); else if (TIMESTAMP_IS_NOEND(timestamp)) DATE_NOEND(result); else { if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0) ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), errmsg("timestamp out of range"))); result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE; } PG_RETURN_DATEADT(result); }
Datum timestamp_eq_date | ( | PG_FUNCTION_ARGS | ) |
Definition at line 693 of file date.c.
References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_BOOL, and timestamp_cmp_internal().
{ Timestamp dt1 = PG_GETARG_TIMESTAMP(0); DateADT dateVal = PG_GETARG_DATEADT(1); Timestamp dt2; dt2 = date2timestamp(dateVal); PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) == 0); }
Datum timestamp_ge_date | ( | PG_FUNCTION_ARGS | ) |
Definition at line 753 of file date.c.
References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_BOOL, and timestamp_cmp_internal().
{ Timestamp dt1 = PG_GETARG_TIMESTAMP(0); DateADT dateVal = PG_GETARG_DATEADT(1); Timestamp dt2; dt2 = date2timestamp(dateVal); PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) >= 0); }
Datum timestamp_gt_date | ( | PG_FUNCTION_ARGS | ) |
Definition at line 729 of file date.c.
References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_BOOL, and timestamp_cmp_internal().
{ Timestamp dt1 = PG_GETARG_TIMESTAMP(0); DateADT dateVal = PG_GETARG_DATEADT(1); Timestamp dt2; dt2 = date2timestamp(dateVal); PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) > 0); }
Datum timestamp_le_date | ( | PG_FUNCTION_ARGS | ) |
Definition at line 741 of file date.c.
References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_BOOL, and timestamp_cmp_internal().
{ Timestamp dt1 = PG_GETARG_TIMESTAMP(0); DateADT dateVal = PG_GETARG_DATEADT(1); Timestamp dt2; dt2 = date2timestamp(dateVal); PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) <= 0); }
Datum timestamp_lt_date | ( | PG_FUNCTION_ARGS | ) |
Definition at line 717 of file date.c.
References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_BOOL, and timestamp_cmp_internal().
{ Timestamp dt1 = PG_GETARG_TIMESTAMP(0); DateADT dateVal = PG_GETARG_DATEADT(1); Timestamp dt2; dt2 = date2timestamp(dateVal); PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) < 0); }
Datum timestamp_ne_date | ( | PG_FUNCTION_ARGS | ) |
Definition at line 705 of file date.c.
References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_BOOL, and timestamp_cmp_internal().
{ Timestamp dt1 = PG_GETARG_TIMESTAMP(0); DateADT dateVal = PG_GETARG_DATEADT(1); Timestamp dt2; dt2 = date2timestamp(dateVal); PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) != 0); }
Datum timestamp_time | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1535 of file date.c.
References ereport, errcode(), errmsg(), ERROR, MINS_PER_HOUR, NULL, PG_GETARG_TIMESTAMP, PG_RETURN_NULL, PG_RETURN_TIMEADT, SECS_PER_MINUTE, timestamp2tm(), TIMESTAMP_NOT_FINITE, tm, pg_tm::tm_hour, pg_tm::tm_min, pg_tm::tm_sec, and USECS_PER_SEC.
{ Timestamp timestamp = PG_GETARG_TIMESTAMP(0); TimeADT result; struct pg_tm tt, *tm = &tt; fsec_t fsec; if (TIMESTAMP_NOT_FINITE(timestamp)) PG_RETURN_NULL(); if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0) ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), errmsg("timestamp out of range"))); #ifdef HAVE_INT64_TIMESTAMP /* * Could also do this with time = (timestamp / USECS_PER_DAY * * USECS_PER_DAY) - timestamp; */ result = ((((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) * USECS_PER_SEC) + fsec; #else result = ((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec + fsec; #endif PG_RETURN_TIMEADT(result); }
Datum timestamptz_cmp_date | ( | PG_FUNCTION_ARGS | ) |
Definition at line 849 of file date.c.
References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_INT32, and timestamptz_cmp_internal.
{ TimestampTz dt1 = PG_GETARG_TIMESTAMPTZ(0); DateADT dateVal = PG_GETARG_DATEADT(1); TimestampTz dt2; dt2 = date2timestamptz(dateVal); PG_RETURN_INT32(timestamptz_cmp_internal(dt1, dt2)); }
Datum timestamptz_date | ( | PG_FUNCTION_ARGS | ) |
Definition at line 964 of file date.c.
References date2j(), DATE_NOBEGIN, DATE_NOEND, ereport, errcode(), errmsg(), ERROR, NULL, PG_GETARG_TIMESTAMP, PG_RETURN_DATEADT, timestamp2tm(), TIMESTAMP_IS_NOBEGIN, TIMESTAMP_IS_NOEND, tm, pg_tm::tm_mday, pg_tm::tm_mon, and pg_tm::tm_year.
{ TimestampTz timestamp = PG_GETARG_TIMESTAMP(0); DateADT result; struct pg_tm tt, *tm = &tt; fsec_t fsec; int tz; if (TIMESTAMP_IS_NOBEGIN(timestamp)) DATE_NOBEGIN(result); else if (TIMESTAMP_IS_NOEND(timestamp)) DATE_NOEND(result); else { if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0) ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), errmsg("timestamp out of range"))); result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE; } PG_RETURN_DATEADT(result); }
Datum timestamptz_eq_date | ( | PG_FUNCTION_ARGS | ) |
Definition at line 777 of file date.c.
References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_BOOL, and timestamptz_cmp_internal.
{ TimestampTz dt1 = PG_GETARG_TIMESTAMPTZ(0); DateADT dateVal = PG_GETARG_DATEADT(1); TimestampTz dt2; dt2 = date2timestamptz(dateVal); PG_RETURN_BOOL(timestamptz_cmp_internal(dt1, dt2) == 0); }
Datum timestamptz_ge_date | ( | PG_FUNCTION_ARGS | ) |
Definition at line 837 of file date.c.
References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_BOOL, and timestamptz_cmp_internal.
{ TimestampTz dt1 = PG_GETARG_TIMESTAMPTZ(0); DateADT dateVal = PG_GETARG_DATEADT(1); TimestampTz dt2; dt2 = date2timestamptz(dateVal); PG_RETURN_BOOL(timestamptz_cmp_internal(dt1, dt2) >= 0); }
Datum timestamptz_gt_date | ( | PG_FUNCTION_ARGS | ) |
Definition at line 813 of file date.c.
References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_BOOL, and timestamptz_cmp_internal.
{ TimestampTz dt1 = PG_GETARG_TIMESTAMPTZ(0); DateADT dateVal = PG_GETARG_DATEADT(1); TimestampTz dt2; dt2 = date2timestamptz(dateVal); PG_RETURN_BOOL(timestamptz_cmp_internal(dt1, dt2) > 0); }
Datum timestamptz_le_date | ( | PG_FUNCTION_ARGS | ) |
Definition at line 825 of file date.c.
References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_BOOL, and timestamptz_cmp_internal.
{ TimestampTz dt1 = PG_GETARG_TIMESTAMPTZ(0); DateADT dateVal = PG_GETARG_DATEADT(1); TimestampTz dt2; dt2 = date2timestamptz(dateVal); PG_RETURN_BOOL(timestamptz_cmp_internal(dt1, dt2) <= 0); }
Datum timestamptz_lt_date | ( | PG_FUNCTION_ARGS | ) |
Definition at line 801 of file date.c.
References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_BOOL, and timestamptz_cmp_internal.
{ TimestampTz dt1 = PG_GETARG_TIMESTAMPTZ(0); DateADT dateVal = PG_GETARG_DATEADT(1); TimestampTz dt2; dt2 = date2timestamptz(dateVal); PG_RETURN_BOOL(timestamptz_cmp_internal(dt1, dt2) < 0); }
Datum timestamptz_ne_date | ( | PG_FUNCTION_ARGS | ) |
Definition at line 789 of file date.c.
References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_BOOL, and timestamptz_cmp_internal.
{ TimestampTz dt1 = PG_GETARG_TIMESTAMPTZ(0); DateADT dateVal = PG_GETARG_DATEADT(1); TimestampTz dt2; dt2 = date2timestamptz(dateVal); PG_RETURN_BOOL(timestamptz_cmp_internal(dt1, dt2) != 0); }
Datum timestamptz_time | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1570 of file date.c.
References ereport, errcode(), errmsg(), ERROR, MINS_PER_HOUR, NULL, PG_GETARG_TIMESTAMP, PG_RETURN_NULL, PG_RETURN_TIMEADT, SECS_PER_MINUTE, timestamp2tm(), TIMESTAMP_NOT_FINITE, tm, pg_tm::tm_hour, pg_tm::tm_min, pg_tm::tm_sec, and USECS_PER_SEC.
{ TimestampTz timestamp = PG_GETARG_TIMESTAMP(0); TimeADT result; struct pg_tm tt, *tm = &tt; int tz; fsec_t fsec; if (TIMESTAMP_NOT_FINITE(timestamp)) PG_RETURN_NULL(); if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0) ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), errmsg("timestamp out of range"))); #ifdef HAVE_INT64_TIMESTAMP /* * Could also do this with time = (timestamp / USECS_PER_DAY * * USECS_PER_DAY) - timestamp; */ result = ((((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) * USECS_PER_SEC) + fsec; #else result = ((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec + fsec; #endif PG_RETURN_TIMEADT(result); }
Datum timestamptz_timetz | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2442 of file date.c.
References ereport, errcode(), errmsg(), ERROR, NULL, palloc(), PG_GETARG_TIMESTAMP, PG_RETURN_NULL, PG_RETURN_TIMETZADT_P, timestamp2tm(), TIMESTAMP_NOT_FINITE, tm, and tm2timetz().
{ TimestampTz timestamp = PG_GETARG_TIMESTAMP(0); TimeTzADT *result; struct pg_tm tt, *tm = &tt; int tz; fsec_t fsec; if (TIMESTAMP_NOT_FINITE(timestamp)) PG_RETURN_NULL(); if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0) ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), errmsg("timestamp out of range"))); result = (TimeTzADT *) palloc(sizeof(TimeTzADT)); tm2timetz(tm, fsec, tz, result); PG_RETURN_TIMETZADT_P(result); }
Datum timetypmodin | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1196 of file date.c.
References anytime_typmodin(), PG_GETARG_ARRAYTYPE_P, and PG_RETURN_INT32.
{ ArrayType *ta = PG_GETARG_ARRAYTYPE_P(0); PG_RETURN_INT32(anytime_typmodin(false, ta)); }
Datum timetypmodout | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1204 of file date.c.
References anytime_typmodout(), PG_GETARG_INT32, and PG_RETURN_CSTRING.
{ int32 typmod = PG_GETARG_INT32(0); PG_RETURN_CSTRING(anytime_typmodout(false, typmod)); }
Datum timetz_cmp | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2151 of file date.c.
References PG_GETARG_TIMETZADT_P, PG_RETURN_INT32, and timetz_cmp_internal().
{ TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); PG_RETURN_INT32(timetz_cmp_internal(time1, time2)); }
Datum timetz_eq | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2097 of file date.c.
References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().
{ TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) == 0); }
Datum timetz_ge | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2142 of file date.c.
References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().
{ TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) >= 0); }
Datum timetz_gt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2133 of file date.c.
References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().
{ TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) > 0); }
Datum timetz_hash | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2160 of file date.c.
References DatumGetUInt32, DirectFunctionCall1, Float8GetDatumFast, hash_uint32(), hashfloat8(), hashint8(), Int64GetDatumFast, PG_GETARG_TIMETZADT_P, PG_RETURN_UINT32, TimeTzADT::time, and TimeTzADT::zone.
{ TimeTzADT *key = PG_GETARG_TIMETZADT_P(0); uint32 thash; /* * To avoid any problems with padding bytes in the struct, we figure the * field hashes separately and XOR them. This also provides a convenient * framework for dealing with the fact that the time field might be either * double or int64. */ #ifdef HAVE_INT64_TIMESTAMP thash = DatumGetUInt32(DirectFunctionCall1(hashint8, Int64GetDatumFast(key->time))); #else thash = DatumGetUInt32(DirectFunctionCall1(hashfloat8, Float8GetDatumFast(key->time))); #endif thash ^= DatumGetUInt32(hash_uint32(key->zone)); PG_RETURN_UINT32(thash); }
Datum timetz_in | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1873 of file date.c.
References AdjustTimeForTypmod(), DateTimeParseError(), DecodeTimeOnly(), MAXDATEFIELDS, MAXDATELEN, palloc(), ParseDateTime(), PG_GETARG_CSTRING, PG_GETARG_INT32, PG_GETARG_OID, PG_RETURN_TIMETZADT_P, TimeTzADT::time, tm, and tm2timetz().
{ char *str = PG_GETARG_CSTRING(0); #ifdef NOT_USED Oid typelem = PG_GETARG_OID(1); #endif int32 typmod = PG_GETARG_INT32(2); TimeTzADT *result; fsec_t fsec; struct pg_tm tt, *tm = &tt; int tz; int nf; int dterr; char workbuf[MAXDATELEN + 1]; char *field[MAXDATEFIELDS]; int dtype; int ftype[MAXDATEFIELDS]; dterr = ParseDateTime(str, workbuf, sizeof(workbuf), field, ftype, MAXDATEFIELDS, &nf); if (dterr == 0) dterr = DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, &tz); if (dterr != 0) DateTimeParseError(dterr, str, "time with time zone"); result = (TimeTzADT *) palloc(sizeof(TimeTzADT)); tm2timetz(tm, fsec, tz, result); AdjustTimeForTypmod(&(result->time), typmod); PG_RETURN_TIMETZADT_P(result); }
Datum timetz_izone | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2692 of file date.c.
References DatumGetCString, Interval::day, DirectFunctionCall1, ereport, errcode(), errmsg(), ERROR, INT64CONST, interval_out(), Interval::month, palloc(), PG_GETARG_INTERVAL_P, PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, PointerGetDatum, SECS_PER_DAY, TimeTzADT::time, Interval::time, USECS_PER_DAY, USECS_PER_SEC, and TimeTzADT::zone.
{ Interval *zone = PG_GETARG_INTERVAL_P(0); TimeTzADT *time = PG_GETARG_TIMETZADT_P(1); TimeTzADT *result; int tz; if (zone->month != 0 || zone->day != 0) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("interval time zone \"%s\" must not include months or days", DatumGetCString(DirectFunctionCall1(interval_out, PointerGetDatum(zone)))))); #ifdef HAVE_INT64_TIMESTAMP tz = -(zone->time / USECS_PER_SEC); #else tz = -(zone->time); #endif result = (TimeTzADT *) palloc(sizeof(TimeTzADT)); #ifdef HAVE_INT64_TIMESTAMP result->time = time->time + (time->zone - tz) * USECS_PER_SEC; while (result->time < INT64CONST(0)) result->time += USECS_PER_DAY; while (result->time >= USECS_PER_DAY) result->time -= USECS_PER_DAY; #else result->time = time->time + (time->zone - tz); while (result->time < 0) result->time += SECS_PER_DAY; while (result->time >= SECS_PER_DAY) result->time -= SECS_PER_DAY; #endif result->zone = tz; PG_RETURN_TIMETZADT_P(result); }
Datum timetz_larger | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2183 of file date.c.
References PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, and timetz_cmp_internal().
{ TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); TimeTzADT *result; if (timetz_cmp_internal(time1, time2) > 0) result = time1; else result = time2; PG_RETURN_TIMETZADT_P(result); }
Datum timetz_le | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2124 of file date.c.
References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().
{ TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) <= 0); }
Datum timetz_lt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2115 of file date.c.
References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().
{ TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) < 0); }
Datum timetz_mi_interval | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2247 of file date.c.
References INT64CONST, palloc(), PG_GETARG_INTERVAL_P, PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, Interval::time, TimeTzADT::time, TMODULO, USECS_PER_DAY, and TimeTzADT::zone.
{ TimeTzADT *time = PG_GETARG_TIMETZADT_P(0); Interval *span = PG_GETARG_INTERVAL_P(1); TimeTzADT *result; #ifndef HAVE_INT64_TIMESTAMP TimeTzADT time1; #endif result = (TimeTzADT *) palloc(sizeof(TimeTzADT)); #ifdef HAVE_INT64_TIMESTAMP result->time = time->time - span->time; result->time -= result->time / USECS_PER_DAY * USECS_PER_DAY; if (result->time < INT64CONST(0)) result->time += USECS_PER_DAY; #else result->time = time->time - span->time; TMODULO(result->time, time1.time, (double) SECS_PER_DAY); if (result->time < 0) result->time += SECS_PER_DAY; #endif result->zone = time->zone; PG_RETURN_TIMETZADT_P(result); }
Datum timetz_ne | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2106 of file date.c.
References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().
{ TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) != 0); }
Datum timetz_out | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1908 of file date.c.
References buf, DateStyle, EncodeTimeOnly(), MAXDATELEN, PG_GETARG_TIMETZADT_P, PG_RETURN_CSTRING, pstrdup(), timetz2tm(), and tm.
{ TimeTzADT *time = PG_GETARG_TIMETZADT_P(0); char *result; struct pg_tm tt, *tm = &tt; fsec_t fsec; int tz; char buf[MAXDATELEN + 1]; timetz2tm(time, tm, &fsec, &tz); EncodeTimeOnly(tm, fsec, true, tz, DateStyle, buf); result = pstrdup(buf); PG_RETURN_CSTRING(result); }
Datum timetz_part | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2501 of file date.c.
References DecodeSpecial(), DecodeUnits(), downcase_truncate_identifier(), DTK_CENTURY, DTK_DAY, DTK_DECADE, DTK_EPOCH, DTK_HOUR, DTK_MICROSEC, DTK_MILLENNIUM, DTK_MILLISEC, DTK_MINUTE, DTK_MONTH, DTK_QUARTER, DTK_SECOND, DTK_TZ, DTK_TZ_HOUR, DTK_TZ_MINUTE, DTK_YEAR, ereport, errcode(), errmsg(), ERROR, FMODULO, PG_GETARG_TEXT_PP, PG_GETARG_TIMETZADT_P, PG_RETURN_FLOAT8, RESERV, SECS_PER_HOUR, SECS_PER_MINUTE, TimeTzADT::time, timetz2tm(), tm, pg_tm::tm_hour, pg_tm::tm_min, pg_tm::tm_sec, UNITS, UNKNOWN_FIELD, val, VARDATA_ANY, VARSIZE_ANY_EXHDR, and TimeTzADT::zone.
{ text *units = PG_GETARG_TEXT_PP(0); TimeTzADT *time = PG_GETARG_TIMETZADT_P(1); float8 result; int type, val; char *lowunits; lowunits = downcase_truncate_identifier(VARDATA_ANY(units), VARSIZE_ANY_EXHDR(units), false); type = DecodeUnits(0, lowunits, &val); if (type == UNKNOWN_FIELD) type = DecodeSpecial(0, lowunits, &val); if (type == UNITS) { double dummy; int tz; fsec_t fsec; struct pg_tm tt, *tm = &tt; timetz2tm(time, tm, &fsec, &tz); switch (val) { case DTK_TZ: result = -tz; break; case DTK_TZ_MINUTE: result = -tz; result /= SECS_PER_MINUTE; FMODULO(result, dummy, (double) SECS_PER_MINUTE); break; case DTK_TZ_HOUR: dummy = -tz; FMODULO(dummy, result, (double) SECS_PER_HOUR); break; case DTK_MICROSEC: #ifdef HAVE_INT64_TIMESTAMP result = tm->tm_sec * 1000000.0 + fsec; #else result = (tm->tm_sec + fsec) * 1000000; #endif break; case DTK_MILLISEC: #ifdef HAVE_INT64_TIMESTAMP result = tm->tm_sec * 1000.0 + fsec / 1000.0; #else result = (tm->tm_sec + fsec) * 1000; #endif break; case DTK_SECOND: #ifdef HAVE_INT64_TIMESTAMP result = tm->tm_sec + fsec / 1000000.0; #else result = tm->tm_sec + fsec; #endif break; case DTK_MINUTE: result = tm->tm_min; break; case DTK_HOUR: result = tm->tm_hour; break; case DTK_DAY: case DTK_MONTH: case DTK_QUARTER: case DTK_YEAR: case DTK_DECADE: case DTK_CENTURY: case DTK_MILLENNIUM: default: ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("\"time with time zone\" units \"%s\" not recognized", lowunits))); result = 0; } } else if (type == RESERV && val == DTK_EPOCH) { #ifdef HAVE_INT64_TIMESTAMP result = time->time / 1000000.0 + time->zone; #else result = time->time + time->zone; #endif } else { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("\"time with time zone\" units \"%s\" not recognized", lowunits))); result = 0; } PG_RETURN_FLOAT8(result); }
Datum timetz_pl_interval | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2214 of file date.c.
References INT64CONST, palloc(), PG_GETARG_INTERVAL_P, PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, Interval::time, TimeTzADT::time, TMODULO, USECS_PER_DAY, and TimeTzADT::zone.
{ TimeTzADT *time = PG_GETARG_TIMETZADT_P(0); Interval *span = PG_GETARG_INTERVAL_P(1); TimeTzADT *result; #ifndef HAVE_INT64_TIMESTAMP TimeTzADT time1; #endif result = (TimeTzADT *) palloc(sizeof(TimeTzADT)); #ifdef HAVE_INT64_TIMESTAMP result->time = time->time + span->time; result->time -= result->time / USECS_PER_DAY * USECS_PER_DAY; if (result->time < INT64CONST(0)) result->time += USECS_PER_DAY; #else result->time = time->time + span->time; TMODULO(result->time, time1.time, (double) SECS_PER_DAY); if (result->time < 0) result->time += SECS_PER_DAY; #endif result->zone = time->zone; PG_RETURN_TIMETZADT_P(result); }
Datum timetz_recv | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1929 of file date.c.
References AdjustTimeForTypmod(), buf, ereport, errcode(), errmsg(), ERROR, INT64CONST, palloc(), PG_GETARG_INT32, PG_GETARG_OID, PG_GETARG_POINTER, PG_RETURN_TIMETZADT_P, pq_getmsgfloat8(), pq_getmsgint(), pq_getmsgint64(), SECS_PER_DAY, TimeTzADT::time, TZDISP_LIMIT, USECS_PER_DAY, and TimeTzADT::zone.
{ StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); #ifdef NOT_USED Oid typelem = PG_GETARG_OID(1); #endif int32 typmod = PG_GETARG_INT32(2); TimeTzADT *result; result = (TimeTzADT *) palloc(sizeof(TimeTzADT)); #ifdef HAVE_INT64_TIMESTAMP result->time = pq_getmsgint64(buf); if (result->time < INT64CONST(0) || result->time > USECS_PER_DAY) ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), errmsg("time out of range"))); #else result->time = pq_getmsgfloat8(buf); if (result->time < 0 || result->time > (double) SECS_PER_DAY) ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), errmsg("time out of range"))); #endif result->zone = pq_getmsgint(buf, sizeof(result->zone)); /* Check for sane GMT displacement; see notes in datatype/timestamp.h */ if (result->zone <= -TZDISP_LIMIT || result->zone >= TZDISP_LIMIT) ereport(ERROR, (errcode(ERRCODE_INVALID_TIME_ZONE_DISPLACEMENT_VALUE), errmsg("time zone displacement out of range"))); AdjustTimeForTypmod(&(result->time), typmod); PG_RETURN_TIMETZADT_P(result); }
Datum timetz_scale | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2047 of file date.c.
References AdjustTimeForTypmod(), palloc(), PG_GETARG_INT32, PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, TimeTzADT::time, and TimeTzADT::zone.
{ TimeTzADT *time = PG_GETARG_TIMETZADT_P(0); int32 typmod = PG_GETARG_INT32(1); TimeTzADT *result; result = (TimeTzADT *) palloc(sizeof(TimeTzADT)); result->time = time->time; result->zone = time->zone; AdjustTimeForTypmod(&(result->time), typmod); PG_RETURN_TIMETZADT_P(result); }
Datum timetz_send | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1974 of file date.c.
References buf, PG_GETARG_TIMETZADT_P, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), pq_sendfloat8(), pq_sendint(), pq_sendint64(), TimeTzADT::time, and TimeTzADT::zone.
{ TimeTzADT *time = PG_GETARG_TIMETZADT_P(0); StringInfoData buf; pq_begintypsend(&buf); #ifdef HAVE_INT64_TIMESTAMP pq_sendint64(&buf, time->time); #else pq_sendfloat8(&buf, time->time); #endif pq_sendint(&buf, time->zone, sizeof(time->zone)); PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); }
Datum timetz_smaller | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2197 of file date.c.
References PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, and timetz_cmp_internal().
{ TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0); TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1); TimeTzADT *result; if (timetz_cmp_internal(time1, time2) < 0) result = time1; else result = time2; PG_RETURN_TIMETZADT_P(result); }
Datum timetz_time | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2403 of file date.c.
References PG_GETARG_TIMETZADT_P, PG_RETURN_TIMEADT, and TimeTzADT::time.
{ TimeTzADT *timetz = PG_GETARG_TIMETZADT_P(0); TimeADT result; /* swallow the time zone and just return the time */ result = timetz->time; PG_RETURN_TIMEADT(result); }
Datum timetz_zone | ( | PG_FUNCTION_ARGS | ) |
Definition at line 2617 of file date.c.
References DecodeSpecial(), downcase_truncate_identifier(), DTZ, ereport, errcode(), errmsg(), ERROR, INT64CONST, now(), NULL, palloc(), PG_GETARG_TEXT_PP, PG_GETARG_TIMETZADT_P, pg_localtime(), PG_RETURN_TIMETZADT_P, pg_tzset(), SECS_PER_DAY, text_to_cstring_buffer(), TimeTzADT::time, tm, pg_tm::tm_gmtoff, TZ, TZ_STRLEN_MAX, USECS_PER_DAY, USECS_PER_SEC, val, and TimeTzADT::zone.
{ text *zone = PG_GETARG_TEXT_PP(0); TimeTzADT *t = PG_GETARG_TIMETZADT_P(1); TimeTzADT *result; int tz; char tzname[TZ_STRLEN_MAX + 1]; char *lowzone; int type, val; pg_tz *tzp; /* * Look up the requested timezone. First we look in the date token table * (to handle cases like "EST"), and if that fails, we look in the * timezone database (to handle cases like "America/New_York"). (This * matches the order in which timestamp input checks the cases; it's * important because the timezone database unwisely uses a few zone names * that are identical to offset abbreviations.) */ text_to_cstring_buffer(zone, tzname, sizeof(tzname)); lowzone = downcase_truncate_identifier(tzname, strlen(tzname), false); type = DecodeSpecial(0, lowzone, &val); if (type == TZ || type == DTZ) tz = val * MINS_PER_HOUR; else { tzp = pg_tzset(tzname); if (tzp) { /* Get the offset-from-GMT that is valid today for the zone */ pg_time_t now = (pg_time_t) time(NULL); struct pg_tm *tm; tm = pg_localtime(&now, tzp); tz = -tm->tm_gmtoff; } else { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("time zone \"%s\" not recognized", tzname))); tz = 0; /* keep compiler quiet */ } } result = (TimeTzADT *) palloc(sizeof(TimeTzADT)); #ifdef HAVE_INT64_TIMESTAMP result->time = t->time + (t->zone - tz) * USECS_PER_SEC; while (result->time < INT64CONST(0)) result->time += USECS_PER_DAY; while (result->time >= USECS_PER_DAY) result->time -= USECS_PER_DAY; #else result->time = t->time + (t->zone - tz); while (result->time < 0) result->time += SECS_PER_DAY; while (result->time >= SECS_PER_DAY) result->time -= SECS_PER_DAY; #endif result->zone = tz; PG_RETURN_TIMETZADT_P(result); }
Datum timetztypmodin | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1990 of file date.c.
References anytime_typmodin(), PG_GETARG_ARRAYTYPE_P, and PG_RETURN_INT32.
{ ArrayType *ta = PG_GETARG_ARRAYTYPE_P(0); PG_RETURN_INT32(anytime_typmodin(true, ta)); }
Datum timetztypmodout | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1998 of file date.c.
References anytime_typmodout(), PG_GETARG_INT32, and PG_RETURN_CSTRING.
{ int32 typmod = PG_GETARG_INT32(0); PG_RETURN_CSTRING(anytime_typmodout(true, typmod)); }