PostgreSQL Source Code git master
Loading...
Searching...
No Matches
date.c File Reference
#include "postgres.h"
#include <ctype.h>
#include <limits.h>
#include <float.h>
#include <math.h>
#include <time.h>
#include "access/xact.h"
#include "catalog/pg_type.h"
#include "common/hashfn.h"
#include "common/int.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
#include "nodes/miscnodes.h"
#include "nodes/supportnodes.h"
#include "parser/scansup.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/date.h"
#include "utils/datetime.h"
#include "utils/numeric.h"
#include "utils/skipsupport.h"
#include "utils/sortsupport.h"
Include dependency graph for date.c:

Go to the source code of this file.

Macros

#define TIMEADT_GT(t1, t2)    (DatumGetTimeADT(t1) > DatumGetTimeADT(t2))
 
#define TIMEADT_LT(t1, t2)    (DatumGetTimeADT(t1) < DatumGetTimeADT(t2))
 
#define TIMETZ_GT(t1, t2)    DatumGetBool(DirectFunctionCall2(timetz_gt,t1,t2))
 
#define TIMETZ_LT(t1, t2)    DatumGetBool(DirectFunctionCall2(timetz_lt,t1,t2))
 

Functions

static int32 anytime_typmodin (bool istz, ArrayType *ta)
 
int32 anytime_typmod_check (bool istz, int32 typmod)
 
static charanytime_typmodout (bool istz, int32 typmod)
 
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 make_date (PG_FUNCTION_ARGS)
 
void EncodeSpecialDate (DateADT dt, char *str)
 
DateADT GetSQLCurrentDate (void)
 
TimeTzADTGetSQLCurrentTime (int32 typmod)
 
TimeADT GetSQLLocalTime (int32 typmod)
 
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)
 
static Datum date_decrement (Relation rel, Datum existing, bool *underflow)
 
static Datum date_increment (Relation rel, Datum existing, bool *overflow)
 
Datum date_skipsupport (PG_FUNCTION_ARGS)
 
Datum hashdate (PG_FUNCTION_ARGS)
 
Datum hashdateextended (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)
 
Timestamp date2timestamp_safe (DateADT dateVal, Node *escontext)
 
static TimestampTz date2timestamp (DateADT dateVal)
 
TimestampTz date2timestamptz_safe (DateADT dateVal, Node *escontext)
 
double date2timestamp_no_overflow (DateADT dateVal)
 
int32 date_cmp_timestamp_internal (DateADT dateVal, Timestamp dt2)
 
Datum date_eq_timestamp (PG_FUNCTION_ARGS)
 
Datum date_ne_timestamp (PG_FUNCTION_ARGS)
 
Datum date_lt_timestamp (PG_FUNCTION_ARGS)
 
Datum date_gt_timestamp (PG_FUNCTION_ARGS)
 
Datum date_le_timestamp (PG_FUNCTION_ARGS)
 
Datum date_ge_timestamp (PG_FUNCTION_ARGS)
 
Datum date_cmp_timestamp (PG_FUNCTION_ARGS)
 
int32 date_cmp_timestamptz_internal (DateADT dateVal, TimestampTz dt2)
 
Datum date_eq_timestamptz (PG_FUNCTION_ARGS)
 
Datum date_ne_timestamptz (PG_FUNCTION_ARGS)
 
Datum date_lt_timestamptz (PG_FUNCTION_ARGS)
 
Datum date_gt_timestamptz (PG_FUNCTION_ARGS)
 
Datum date_le_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_gt_date (PG_FUNCTION_ARGS)
 
Datum timestamp_le_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_gt_date (PG_FUNCTION_ARGS)
 
Datum timestamptz_le_date (PG_FUNCTION_ARGS)
 
Datum timestamptz_ge_date (PG_FUNCTION_ARGS)
 
Datum timestamptz_cmp_date (PG_FUNCTION_ARGS)
 
Datum in_range_date_interval (PG_FUNCTION_ARGS)
 
Datum extract_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)
 
DateADT timestamp2date_safe (Timestamp timestamp, Node *escontext)
 
Datum date_timestamptz (PG_FUNCTION_ARGS)
 
Datum timestamptz_date (PG_FUNCTION_ARGS)
 
DateADT timestamptz2date_safe (TimestampTz timestamp, Node *escontext)
 
Datum time_in (PG_FUNCTION_ARGS)
 
int tm2time (struct pg_tm *tm, fsec_t fsec, TimeADT *result)
 
bool time_overflows (int hour, int min, int sec, fsec_t fsec)
 
bool float_time_overflows (int hour, int min, double sec)
 
int time2tm (TimeADT time, struct pg_tm *tm, fsec_t *fsec)
 
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 make_time (PG_FUNCTION_ARGS)
 
Datum time_support (PG_FUNCTION_ARGS)
 
Datum time_scale (PG_FUNCTION_ARGS)
 
void AdjustTimeForTypmod (TimeADT *time, int32 typmod)
 
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 time_hash_extended (PG_FUNCTION_ARGS)
 
Datum time_larger (PG_FUNCTION_ARGS)
 
Datum time_smaller (PG_FUNCTION_ARGS)
 
Datum overlaps_time (PG_FUNCTION_ARGS)
 
Datum timestamp_time (PG_FUNCTION_ARGS)
 
Datum timestamptz_time (PG_FUNCTION_ARGS)
 
Datum datetime_timestamp (PG_FUNCTION_ARGS)
 
Datum time_interval (PG_FUNCTION_ARGS)
 
Datum interval_time (PG_FUNCTION_ARGS)
 
Datum time_mi_time (PG_FUNCTION_ARGS)
 
Datum time_pl_interval (PG_FUNCTION_ARGS)
 
Datum time_mi_interval (PG_FUNCTION_ARGS)
 
Datum in_range_time_interval (PG_FUNCTION_ARGS)
 
static Datum time_part_common (PG_FUNCTION_ARGS, bool retnumeric)
 
Datum time_part (PG_FUNCTION_ARGS)
 
Datum extract_time (PG_FUNCTION_ARGS)
 
int tm2timetz (struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
 
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)
 
int timetz2tm (TimeTzADT *time, struct pg_tm *tm, fsec_t *fsec, int *tzp)
 
Datum timetz_scale (PG_FUNCTION_ARGS)
 
static int timetz_cmp_internal (TimeTzADT *time1, TimeTzADT *time2)
 
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 timetz_hash_extended (PG_FUNCTION_ARGS)
 
Datum timetz_larger (PG_FUNCTION_ARGS)
 
Datum timetz_smaller (PG_FUNCTION_ARGS)
 
Datum timetz_pl_interval (PG_FUNCTION_ARGS)
 
Datum timetz_mi_interval (PG_FUNCTION_ARGS)
 
Datum in_range_timetz_interval (PG_FUNCTION_ARGS)
 
Datum overlaps_timetz (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)
 
static Datum timetz_part_common (PG_FUNCTION_ARGS, bool retnumeric)
 
Datum timetz_part (PG_FUNCTION_ARGS)
 
Datum extract_timetz (PG_FUNCTION_ARGS)
 
Datum timetz_zone (PG_FUNCTION_ARGS)
 
Datum timetz_izone (PG_FUNCTION_ARGS)
 
Datum timetz_at_local (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

◆ TIMEADT_GT

#define TIMEADT_GT (   t1,
  t2 
)     (DatumGetTimeADT(t1) > DatumGetTimeADT(t2))

◆ TIMEADT_LT

#define TIMEADT_LT (   t1,
  t2 
)     (DatumGetTimeADT(t1) < DatumGetTimeADT(t2))

◆ TIMETZ_GT

#define TIMETZ_GT (   t1,
  t2 
)     DatumGetBool(DirectFunctionCall2(timetz_gt,t1,t2))

◆ TIMETZ_LT

#define TIMETZ_LT (   t1,
  t2 
)     DatumGetBool(DirectFunctionCall2(timetz_lt,t1,t2))

Function Documentation

◆ AdjustTimeForTypmod()

void AdjustTimeForTypmod ( TimeADT time,
int32  typmod 
)

Definition at line 1753 of file date.c.

1754{
1755 static const int64 TimeScales[MAX_TIME_PRECISION + 1] = {
1756 INT64CONST(1000000),
1757 INT64CONST(100000),
1758 INT64CONST(10000),
1759 INT64CONST(1000),
1760 INT64CONST(100),
1761 INT64CONST(10),
1762 INT64CONST(1)
1763 };
1764
1765 static const int64 TimeOffsets[MAX_TIME_PRECISION + 1] = {
1766 INT64CONST(500000),
1767 INT64CONST(50000),
1768 INT64CONST(5000),
1769 INT64CONST(500),
1770 INT64CONST(50),
1771 INT64CONST(5),
1772 INT64CONST(0)
1773 };
1774
1775 if (typmod >= 0 && typmod <= MAX_TIME_PRECISION)
1776 {
1777 if (*time >= INT64CONST(0))
1778 *time = ((*time + TimeOffsets[typmod]) / TimeScales[typmod]) *
1779 TimeScales[typmod];
1780 else
1781 *time = -((((-*time) + TimeOffsets[typmod]) / TimeScales[typmod]) *
1782 TimeScales[typmod]);
1783 }
1784}
#define INT64CONST(x)
Definition c.h:630
int64_t int64
Definition c.h:621
#define MAX_TIME_PRECISION
Definition date.h:51
static int fb(int x)

References fb(), INT64CONST, and MAX_TIME_PRECISION.

Referenced by executeDateTimeMethod(), GetSQLCurrentTime(), GetSQLLocalTime(), parse_datetime(), time_in(), time_recv(), time_scale(), timetz_in(), timetz_recv(), and timetz_scale().

◆ anytime_typmod_check()

int32 anytime_typmod_check ( bool  istz,
int32  typmod 
)

Definition at line 65 of file date.c.

66{
67 if (typmod < 0)
70 errmsg("TIME(%d)%s precision must not be negative",
71 typmod, (istz ? " WITH TIME ZONE" : ""))));
72 if (typmod > MAX_TIME_PRECISION)
73 {
76 errmsg("TIME(%d)%s precision reduced to maximum allowed, %d",
77 typmod, (istz ? " WITH TIME ZONE" : ""),
79 typmod = MAX_TIME_PRECISION;
80 }
81
82 return typmod;
83}
int errcode(int sqlerrcode)
Definition elog.c:875
#define WARNING
Definition elog.h:37
#define ERROR
Definition elog.h:40
#define ereport(elevel,...)
Definition elog.h:152
static char * errmsg

References ereport, errcode(), errmsg, ERROR, fb(), MAX_TIME_PRECISION, and WARNING.

Referenced by anytime_typmodin(), executeDateTimeMethod(), and transformSQLValueFunction().

◆ anytime_typmodin()

static int32 anytime_typmodin ( bool  istz,
ArrayType ta 
)
static

Definition at line 44 of file date.c.

45{
46 int32 *tl;
47 int n;
48
50
51 /*
52 * we're not too tense about good error message here because grammar
53 * shouldn't allow wrong number of modifiers for TIME
54 */
55 if (n != 1)
58 errmsg("invalid type modifier")));
59
60 return anytime_typmod_check(istz, tl[0]);
61}
int32 * ArrayGetIntegerTypmods(ArrayType *arr, int *n)
Definition arrayutils.c:233
int32_t int32
Definition c.h:620
int32 anytime_typmod_check(bool istz, int32 typmod)
Definition date.c:65

References anytime_typmod_check(), ArrayGetIntegerTypmods(), ereport, errcode(), errmsg, ERROR, and fb().

Referenced by timetypmodin(), and timetztypmodin().

◆ anytime_typmodout()

static char * anytime_typmodout ( bool  istz,
int32  typmod 
)
static

Definition at line 87 of file date.c.

88{
89 const char *tz = istz ? " with time zone" : " without time zone";
90
91 if (typmod >= 0)
92 return psprintf("(%d)%s", (int) typmod, tz);
93 else
94 return pstrdup(tz);
95}
char * pstrdup(const char *in)
Definition mcxt.c:1910
char * psprintf(const char *fmt,...)
Definition psprintf.c:43

References fb(), psprintf(), and pstrdup().

Referenced by timetypmodout(), and timetztypmodout().

◆ date2timestamp()

static TimestampTz date2timestamp ( DateADT  dateVal)
static

Definition at line 660 of file date.c.

661{
663}
Timestamp date2timestamp_safe(DateADT dateVal, Node *escontext)
Definition date.c:627

References date2timestamp_safe(), and fb().

Referenced by date_mi_interval(), date_pl_interval(), datetime_timestamp(), and in_range_date_interval().

◆ date2timestamp_no_overflow()

double date2timestamp_no_overflow ( DateADT  dateVal)

Definition at line 741 of file date.c.

742{
743 double result;
744
746 result = -DBL_MAX;
747 else if (DATE_IS_NOEND(dateVal))
748 result = DBL_MAX;
749 else
750 {
751 /* date is days since 2000, timestamp is microseconds since same... */
753 }
754
755 return result;
756}
uint32 result
#define USECS_PER_DAY
Definition timestamp.h:131
#define DATE_IS_NOEND(j)
Definition date.h:48
#define DATE_IS_NOBEGIN(j)
Definition date.h:46

References DATE_IS_NOBEGIN, DATE_IS_NOEND, fb(), result, and USECS_PER_DAY.

Referenced by convert_timevalue_to_scalar().

◆ date2timestamp_safe()

Timestamp date2timestamp_safe ( DateADT  dateVal,
Node escontext 
)

Definition at line 627 of file date.c.

628{
630
633 else if (DATE_IS_NOEND(dateVal))
635 else
636 {
637 /*
638 * Since dates have the same minimum values as timestamps, only upper
639 * boundary need be checked for overflow.
640 */
642 {
644 ereturn(escontext, result,
646 errmsg("date out of range for timestamp")));
647 }
648
649 /* date is days since 2000, timestamp is microseconds since same... */
651 }
652
653 return result;
654}
int64 Timestamp
Definition timestamp.h:38
#define TIMESTAMP_NOBEGIN(j)
Definition timestamp.h:159
#define TIMESTAMP_END_JULIAN
Definition timestamp.h:253
#define POSTGRES_EPOCH_JDATE
Definition timestamp.h:235
#define TIMESTAMP_NOEND(j)
Definition timestamp.h:164
#define ereturn(context, dummy_value,...)
Definition elog.h:280

References DATE_IS_NOBEGIN, DATE_IS_NOEND, ereturn, errcode(), errmsg, fb(), POSTGRES_EPOCH_JDATE, result, TIMESTAMP_END_JULIAN, TIMESTAMP_NOBEGIN, TIMESTAMP_NOEND, and USECS_PER_DAY.

Referenced by cvt_date_timestamp(), date2timestamp(), date_cmp_timestamp_internal(), and date_timestamp().

◆ date2timestamptz_safe()

TimestampTz date2timestamptz_safe ( DateADT  dateVal,
Node escontext 
)

Definition at line 676 of file date.c.

677{
679 struct pg_tm tt,
680 *tm = &tt;
681 int tz;
682
685 else if (DATE_IS_NOEND(dateVal))
687 else
688 {
689 /*
690 * Since dates have the same minimum values as timestamps, only upper
691 * boundary need be checked for overflow.
692 */
694 {
696 ereturn(escontext, result,
698 errmsg("date out of range for timestamp")));
699 }
700
702 &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
703 tm->tm_hour = 0;
704 tm->tm_min = 0;
705 tm->tm_sec = 0;
707
709
710 /*
711 * Since it is possible to go beyond allowed timestamptz range because
712 * of time zone, check for allowed timestamp range after adding tz.
713 */
715 {
716 if (result < MIN_TIMESTAMP)
718 else
720
721 ereturn(escontext, result,
723 errmsg("date out of range for timestamp")));
724 }
725 }
726
727 return result;
728}
int DetermineTimeZoneOffset(struct pg_tm *tm, pg_tz *tzp)
Definition datetime.c:1608
void j2date(int jd, int *year, int *month, int *day)
Definition datetime.c:322
int64 TimestampTz
Definition timestamp.h:39
#define IS_VALID_TIMESTAMP(t)
Definition timestamp.h:267
#define USECS_PER_SEC
Definition timestamp.h:134
#define MIN_TIMESTAMP
Definition timestamp.h:256
static struct pg_tm tm
Definition localtime.c:104
PGDLLIMPORT pg_tz * session_timezone
Definition pgtz.c:28
Definition pgtime.h:35
int tm_hour
Definition pgtime.h:38
int tm_mday
Definition pgtime.h:39
int tm_mon
Definition pgtime.h:40
int tm_min
Definition pgtime.h:37
int tm_sec
Definition pgtime.h:36
int tm_year
Definition pgtime.h:41

References DATE_IS_NOBEGIN, DATE_IS_NOEND, DetermineTimeZoneOffset(), ereturn, errcode(), errmsg, fb(), IS_VALID_TIMESTAMP, j2date(), MIN_TIMESTAMP, POSTGRES_EPOCH_JDATE, result, session_timezone, TIMESTAMP_END_JULIAN, TIMESTAMP_NOBEGIN, TIMESTAMP_NOEND, tm, pg_tm::tm_hour, pg_tm::tm_mday, pg_tm::tm_min, pg_tm::tm_mon, pg_tm::tm_sec, pg_tm::tm_year, USECS_PER_DAY, and USECS_PER_SEC.

Referenced by cvt_date_timestamptz(), date_cmp_timestamptz_internal(), and date_timestamptz().

◆ date_cmp()

Datum date_cmp ( PG_FUNCTION_ARGS  )

Definition at line 440 of file date.c.

441{
444
445 if (dateVal1 < dateVal2)
446 PG_RETURN_INT32(-1);
447 else if (dateVal1 > dateVal2)
450}
int32 DateADT
Definition date.h:21
#define PG_GETARG_DATEADT(n)
Definition date.h:95
#define PG_RETURN_INT32(x)
Definition fmgr.h:355

References fb(), PG_GETARG_DATEADT, and PG_RETURN_INT32.

Referenced by compareDatetime(), gbt_date_ssup_cmp(), and gbt_datekey_cmp().

◆ date_cmp_timestamp()

Datum date_cmp_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 836 of file date.c.

837{
840
842}
int32 date_cmp_timestamp_internal(DateADT dateVal, Timestamp dt2)
Definition date.c:764
#define PG_GETARG_TIMESTAMP(n)
Definition timestamp.h:63

References date_cmp_timestamp_internal(), fb(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, and PG_RETURN_INT32.

◆ date_cmp_timestamp_internal()

int32 date_cmp_timestamp_internal ( DateADT  dateVal,
Timestamp  dt2 
)

Definition at line 764 of file date.c.

765{
768
769 dt1 = date2timestamp_safe(dateVal, (Node *) &escontext);
770 if (escontext.error_occurred)
771 {
772 Assert(TIMESTAMP_IS_NOEND(dt1)); /* NOBEGIN case cannot occur */
773
774 /* dt1 is larger than any finite timestamp, but less than infinity */
775 return TIMESTAMP_IS_NOEND(dt2) ? -1 : +1;
776 }
777
779}
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition timestamp.c:2222
#define Assert(condition)
Definition c.h:943
#define TIMESTAMP_IS_NOEND(j)
Definition timestamp.h:167
Definition nodes.h:135

References Assert, date2timestamp_safe(), ErrorSaveContext::error_occurred, fb(), timestamp_cmp_internal(), and TIMESTAMP_IS_NOEND.

Referenced by cmpDateToTimestamp(), date_cmp_timestamp(), date_eq_timestamp(), date_ge_timestamp(), date_gt_timestamp(), date_le_timestamp(), date_lt_timestamp(), date_ne_timestamp(), timestamp_cmp_date(), timestamp_eq_date(), timestamp_ge_date(), timestamp_gt_date(), timestamp_le_date(), timestamp_lt_date(), and timestamp_ne_date().

◆ date_cmp_timestamptz()

Datum date_cmp_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 924 of file date.c.

925{
928
930}
int32 date_cmp_timestamptz_internal(DateADT dateVal, TimestampTz dt2)
Definition date.c:845
#define PG_GETARG_TIMESTAMPTZ(n)
Definition timestamp.h:64

References date_cmp_timestamptz_internal(), fb(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, and PG_RETURN_INT32.

◆ date_cmp_timestamptz_internal()

int32 date_cmp_timestamptz_internal ( DateADT  dateVal,
TimestampTz  dt2 
)

Definition at line 845 of file date.c.

846{
849
850 dt1 = date2timestamptz_safe(dateVal, (Node *) &escontext);
851
852 if (escontext.error_occurred)
853 {
855 {
856 /* dt1 is larger than any finite timestamp, but less than infinity */
857 return TIMESTAMP_IS_NOEND(dt2) ? -1 : +1;
858 }
860 {
861 /* dt1 is less than any finite timestamp, but more than -infinity */
862 return TIMESTAMP_IS_NOBEGIN(dt2) ? +1 : -1;
863 }
864 }
865
867}
#define TIMESTAMP_IS_NOBEGIN(j)
Definition timestamp.h:162
TimestampTz date2timestamptz_safe(DateADT dateVal, Node *escontext)
Definition date.c:676
#define timestamptz_cmp_internal(dt1, dt2)
Definition timestamp.h:143

References date2timestamptz_safe(), ErrorSaveContext::error_occurred, fb(), TIMESTAMP_IS_NOBEGIN, TIMESTAMP_IS_NOEND, and timestamptz_cmp_internal.

Referenced by cmpDateToTimestampTz(), date_cmp_timestamptz(), date_eq_timestamptz(), date_ge_timestamptz(), date_gt_timestamptz(), date_le_timestamptz(), date_lt_timestamptz(), date_ne_timestamptz(), timestamptz_cmp_date(), timestamptz_eq_date(), timestamptz_ge_date(), timestamptz_gt_date(), timestamptz_le_date(), timestamptz_lt_date(), and timestamptz_ne_date().

◆ date_decrement()

static Datum date_decrement ( Relation  rel,
Datum  existing,
bool underflow 
)
static

Definition at line 462 of file date.c.

463{
465
467 {
468 /* return value is undefined */
469 *underflow = true;
470 return (Datum) 0;
471 }
472
473 *underflow = false;
474 return DateADTGetDatum(dexisting - 1);
475}
static Datum DateADTGetDatum(DateADT X)
Definition date.h:78
static DateADT DatumGetDateADT(Datum X)
Definition date.h:60
#define DATEVAL_NOBEGIN
Definition date.h:42
uint64_t Datum
Definition postgres.h:70

References DateADTGetDatum(), DATEVAL_NOBEGIN, DatumGetDateADT(), and fb().

Referenced by date_skipsupport().

◆ date_eq()

Datum date_eq ( PG_FUNCTION_ARGS  )

Definition at line 386 of file date.c.

387{
390
392}
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360

References fb(), PG_GETARG_DATEADT, and PG_RETURN_BOOL.

Referenced by gbt_dateeq().

◆ date_eq_timestamp()

◆ date_eq_timestamptz()

◆ date_finite()

Datum date_finite ( PG_FUNCTION_ARGS  )

Definition at line 519 of file date.c.

520{
522
524}
#define DATE_NOT_FINITE(j)
Definition date.h:49
long date
Definition pgtypes_date.h:9

References DATE_NOT_FINITE, PG_GETARG_DATEADT, and PG_RETURN_BOOL.

◆ date_ge()

Datum date_ge ( PG_FUNCTION_ARGS  )

Definition at line 431 of file date.c.

References fb(), PG_GETARG_DATEADT, and PG_RETURN_BOOL.

Referenced by gbt_datege().

◆ date_ge_timestamp()

◆ date_ge_timestamptz()

◆ date_gt()

Datum date_gt ( PG_FUNCTION_ARGS  )

Definition at line 422 of file date.c.

References fb(), PG_GETARG_DATEADT, and PG_RETURN_BOOL.

Referenced by gbt_dategt().

◆ date_gt_timestamp()

◆ date_gt_timestamptz()

◆ date_in()

Datum date_in ( PG_FUNCTION_ARGS  )

Definition at line 108 of file date.c.

109{
110 char *str = PG_GETARG_CSTRING(0);
111 Node *escontext = fcinfo->context;
113 fsec_t fsec;
114 struct pg_tm tt,
115 *tm = &tt;
116 int tzp;
117 int dtype;
118 int nf;
119 int dterr;
120 char *field[MAXDATEFIELDS];
121 int ftype[MAXDATEFIELDS];
122 char workbuf[MAXDATELEN + 1];
123 DateTimeErrorExtra extra;
124
126 field, ftype, MAXDATEFIELDS, &nf);
127 if (dterr == 0)
128 dterr = DecodeDateTime(field, ftype, nf,
129 &dtype, tm, &fsec, &tzp, &extra);
130 if (dterr != 0)
131 {
132 DateTimeParseError(dterr, &extra, str, "date", escontext);
134 }
135
136 switch (dtype)
137 {
138 case DTK_DATE:
139 break;
140
141 case DTK_EPOCH:
143 break;
144
145 case DTK_LATE:
148
149 case DTK_EARLY:
152
153 default:
154 DateTimeParseError(DTERR_BAD_FORMAT, &extra, str, "date", escontext);
156 }
157
158 /* Prevent overflow in Julian-day routines */
160 ereturn(escontext, (Datum) 0,
162 errmsg("date out of range: \"%s\"", str)));
163
165
166 /* Now check for just-out-of-range dates */
167 if (!IS_VALID_DATE(date))
168 ereturn(escontext, (Datum) 0,
170 errmsg("date out of range: \"%s\"", str)));
171
173}
int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, char **field, int *ftype, int maxfields, int *numfields)
Definition datetime.c:775
void DateTimeParseError(int dterr, DateTimeErrorExtra *extra, const char *str, const char *datatype, Node *escontext)
Definition datetime.c:4241
int DecodeDateTime(char **field, int *ftype, int nf, int *dtype, struct pg_tm *tm, fsec_t *fsec, int *tzp, DateTimeErrorExtra *extra)
Definition datetime.c:1000
int date2j(int year, int month, int day)
Definition datetime.c:297
void GetEpochTime(struct pg_tm *tm)
Definition timestamp.c:2180
#define IS_VALID_DATE(d)
Definition timestamp.h:262
int32 fsec_t
Definition timestamp.h:41
#define IS_VALID_JULIAN(y, m, d)
Definition timestamp.h:227
#define PG_RETURN_DATEADT(x)
Definition date.h:99
#define DATE_NOEND(j)
Definition date.h:47
#define DATE_NOBEGIN(j)
Definition date.h:45
#define PG_GETARG_CSTRING(n)
Definition fmgr.h:278
#define PG_RETURN_NULL()
Definition fmgr.h:346
const char * str
#define MAXDATEFIELDS
Definition datetime.h:202
#define DTK_EPOCH
Definition datetime.h:152
#define DTK_LATE
Definition datetime.h:151
#define DTK_DATE
Definition datetime.h:144
#define DTERR_BAD_FORMAT
Definition datetime.h:284
#define DTK_EARLY
Definition datetime.h:150
#define MAXDATELEN
Definition datetime.h:200

References date2j(), DATE_NOBEGIN, DATE_NOEND, DateTimeParseError(), DecodeDateTime(), DTERR_BAD_FORMAT, DTK_DATE, DTK_EARLY, DTK_EPOCH, DTK_LATE, ereturn, errcode(), errmsg, fb(), GetEpochTime(), IS_VALID_DATE, IS_VALID_JULIAN, MAXDATEFIELDS, MAXDATELEN, ParseDateTime(), PG_GETARG_CSTRING, PG_RETURN_DATEADT, PG_RETURN_NULL, POSTGRES_EPOCH_JDATE, str, tm, pg_tm::tm_mday, pg_tm::tm_mon, and pg_tm::tm_year.

◆ date_increment()

static Datum date_increment ( Relation  rel,
Datum  existing,
bool overflow 
)
static

Definition at line 478 of file date.c.

479{
481
483 {
484 /* return value is undefined */
485 *overflow = true;
486 return (Datum) 0;
487 }
488
489 *overflow = false;
490 return DateADTGetDatum(dexisting + 1);
491}
#define DATEVAL_NOEND
Definition date.h:43

References DateADTGetDatum(), DATEVAL_NOEND, DatumGetDateADT(), and fb().

Referenced by date_skipsupport().

◆ date_larger()

Datum date_larger ( PG_FUNCTION_ARGS  )

Definition at line 527 of file date.c.

References fb(), PG_GETARG_DATEADT, and PG_RETURN_DATEADT.

◆ date_le()

Datum date_le ( PG_FUNCTION_ARGS  )

Definition at line 413 of file date.c.

References fb(), PG_GETARG_DATEADT, and PG_RETURN_BOOL.

Referenced by gbt_datele().

◆ date_le_timestamp()

◆ date_le_timestamptz()

◆ date_lt()

Datum date_lt ( PG_FUNCTION_ARGS  )

Definition at line 404 of file date.c.

References fb(), PG_GETARG_DATEADT, and PG_RETURN_BOOL.

Referenced by gbt_datelt().

◆ date_lt_timestamp()

◆ date_lt_timestamptz()

◆ date_mi()

◆ date_mi_interval()

Datum date_mi_interval ( PG_FUNCTION_ARGS  )

Definition at line 1295 of file date.c.

1296{
1300
1302
1306}
Datum timestamp_mi_interval(PG_FUNCTION_ARGS)
Definition timestamp.c:3221
static TimestampTz date2timestamp(DateADT dateVal)
Definition date.c:660
#define DirectFunctionCall2(func, arg1, arg2)
Definition fmgr.h:690
#define PointerGetDatum(X)
Definition postgres.h:354
static Datum TimestampGetDatum(Timestamp X)
Definition timestamp.h:46
#define PG_GETARG_INTERVAL_P(n)
Definition timestamp.h:65

References date2timestamp(), DirectFunctionCall2, fb(), PG_GETARG_DATEADT, PG_GETARG_INTERVAL_P, PointerGetDatum, timestamp_mi_interval(), and TimestampGetDatum().

◆ date_mii()

Datum date_mii ( PG_FUNCTION_ARGS  )

Definition at line 591 of file date.c.

592{
596
598 PG_RETURN_DATEADT(dateVal); /* can't change infinity */
599
600 result = dateVal - days;
601
602 /* Check for integer overflow and out-of-allowed-range */
603 if ((days >= 0 ? (result > dateVal) : (result < dateVal)) ||
607 errmsg("date out of range")));
608
610}
const char *const days[]
Definition datetime.c:85
#define PG_GETARG_INT32(n)
Definition fmgr.h:269

References DATE_NOT_FINITE, days, ereport, errcode(), errmsg, ERROR, fb(), IS_VALID_DATE, PG_GETARG_DATEADT, PG_GETARG_INT32, PG_RETURN_DATEADT, and result.

◆ date_ne()

Datum date_ne ( PG_FUNCTION_ARGS  )

Definition at line 395 of file date.c.

References fb(), PG_GETARG_DATEADT, and PG_RETURN_BOOL.

◆ date_ne_timestamp()

◆ date_ne_timestamptz()

◆ date_out()

Datum date_out ( PG_FUNCTION_ARGS  )

Definition at line 180 of file date.c.

181{
183 char *result;
184 struct pg_tm tt,
185 *tm = &tt;
186 char buf[MAXDATELEN + 1];
187
190 else
191 {
193 &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
195 }
196
197 result = pstrdup(buf);
199}
void EncodeDateOnly(struct pg_tm *tm, int style, char *str)
Definition datetime.c:4379
void EncodeSpecialDate(DateADT dt, char *str)
Definition date.c:297
#define PG_RETURN_CSTRING(x)
Definition fmgr.h:364
int DateStyle
Definition globals.c:127
static char buf[DEFAULT_XLOG_SEG_SIZE]

References buf, DATE_NOT_FINITE, DateStyle, EncodeDateOnly(), EncodeSpecialDate(), fb(), j2date(), MAXDATELEN, PG_GETARG_DATEADT, PG_RETURN_CSTRING, POSTGRES_EPOCH_JDATE, pstrdup(), result, tm, pg_tm::tm_mday, pg_tm::tm_mon, and pg_tm::tm_year.

Referenced by ExecGetJsonValueItemString().

◆ date_pl_interval()

◆ date_pli()

Datum date_pli ( PG_FUNCTION_ARGS  )

Definition at line 566 of file date.c.

567{
571
573 PG_RETURN_DATEADT(dateVal); /* can't change infinity */
574
575 result = dateVal + days;
576
577 /* Check for integer overflow and out-of-allowed-range */
578 if ((days >= 0 ? (result < dateVal) : (result > dateVal)) ||
582 errmsg("date out of range")));
583
585}

References DATE_NOT_FINITE, days, ereport, errcode(), errmsg, ERROR, fb(), IS_VALID_DATE, PG_GETARG_DATEADT, PG_GETARG_INT32, PG_RETURN_DATEADT, and result.

◆ date_recv()

Datum date_recv ( PG_FUNCTION_ARGS  )

Definition at line 205 of file date.c.

206{
209
210 result = (DateADT) pq_getmsgint(buf, sizeof(DateADT));
211
212 /* Limit to the same range that date_in() accepts. */
214 /* ok */ ;
215 else if (!IS_VALID_DATE(result))
218 errmsg("date out of range")));
219
221}
#define PG_GETARG_POINTER(n)
Definition fmgr.h:277
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition pqformat.c:414
struct StringInfoData * StringInfo
Definition string.h:15

References buf, DATE_NOT_FINITE, ereport, errcode(), errmsg, ERROR, fb(), IS_VALID_DATE, PG_GETARG_POINTER, PG_RETURN_DATEADT, pq_getmsgint(), and result.

◆ date_send()

Datum date_send ( PG_FUNCTION_ARGS  )

Definition at line 227 of file date.c.

228{
231
235}
#define PG_RETURN_BYTEA_P(x)
Definition fmgr.h:373
void pq_begintypsend(StringInfo buf)
Definition pqformat.c:325
bytea * pq_endtypsend(StringInfo buf)
Definition pqformat.c:345
static void pq_sendint32(StringInfo buf, uint32 i)
Definition pqformat.h:144

References buf, PG_GETARG_DATEADT, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint32().

◆ date_skipsupport()

Datum date_skipsupport ( PG_FUNCTION_ARGS  )

Definition at line 494 of file date.c.

495{
497
498 sksup->decrement = date_decrement;
499 sksup->increment = date_increment;
502
504}
static Datum date_decrement(Relation rel, Datum existing, bool *underflow)
Definition date.c:462
static Datum date_increment(Relation rel, Datum existing, bool *overflow)
Definition date.c:478
#define PG_RETURN_VOID()
Definition fmgr.h:350
struct SkipSupportData * SkipSupport
Definition skipsupport.h:50
SkipSupportIncDec decrement
Definition skipsupport.h:91
SkipSupportIncDec increment
Definition skipsupport.h:92

References date_decrement(), date_increment(), DateADTGetDatum(), DATEVAL_NOBEGIN, DATEVAL_NOEND, SkipSupportData::decrement, SkipSupportData::high_elem, SkipSupportData::increment, SkipSupportData::low_elem, PG_GETARG_POINTER, and PG_RETURN_VOID.

◆ date_smaller()

Datum date_smaller ( PG_FUNCTION_ARGS  )

Definition at line 536 of file date.c.

References fb(), PG_GETARG_DATEADT, and PG_RETURN_DATEADT.

◆ date_sortsupport()

Datum date_sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 453 of file date.c.

454{
456
459}
struct SortSupportData * SortSupport
Definition execnodes.h:61
int(* comparator)(Datum x, Datum y, SortSupport ssup)
int ssup_datum_int32_cmp(Datum x, Datum y, SortSupport ssup)
Definition tuplesort.c:3475

References SortSupportData::comparator, PG_GETARG_POINTER, PG_RETURN_VOID, and ssup_datum_int32_cmp().

◆ date_timestamp()

Datum date_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 1313 of file date.c.

1314{
1317
1318 result = date2timestamp_safe(dateVal, fcinfo->context);
1319 if (SOFT_ERROR_OCCURRED(fcinfo->context))
1321
1323}
#define SOFT_ERROR_OCCURRED(escontext)
Definition miscnodes.h:53
#define PG_RETURN_TIMESTAMP(x)
Definition timestamp.h:67

References date2timestamp_safe(), fb(), PG_GETARG_DATEADT, PG_RETURN_NULL, PG_RETURN_TIMESTAMP, result, and SOFT_ERROR_OCCURRED.

Referenced by executeDateTimeMethod().

◆ date_timestamptz()

Datum date_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 1393 of file date.c.

1394{
1397
1398 result = date2timestamptz_safe(dateVal, fcinfo->context);
1399 if (SOFT_ERROR_OCCURRED(fcinfo->context))
1401
1403}

References date2timestamptz_safe(), fb(), PG_GETARG_DATEADT, PG_RETURN_NULL, PG_RETURN_TIMESTAMP, result, and SOFT_ERROR_OCCURRED.

Referenced by executeDateTimeMethod().

◆ datetime_timestamp()

Datum datetime_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 2078 of file date.c.

2079{
2081 TimeADT time = PG_GETARG_TIMEADT(1);
2083
2086 {
2087 result += time;
2089 ereport(ERROR,
2091 errmsg("timestamp out of range")));
2092 }
2093
2095}
#define TIMESTAMP_NOT_FINITE(j)
Definition timestamp.h:169
#define PG_GETARG_TIMEADT(n)
Definition date.h:96
int64 TimeADT
Definition date.h:23

References date2timestamp(), ereport, errcode(), errmsg, ERROR, fb(), IS_VALID_TIMESTAMP, PG_GETARG_DATEADT, PG_GETARG_TIMEADT, PG_RETURN_TIMESTAMP, result, and TIMESTAMP_NOT_FINITE.

◆ datetimetz_timestamptz()

Datum datetimetz_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 3012 of file date.c.

3013{
3017
3018 if (DATE_IS_NOBEGIN(date))
3020 else if (DATE_IS_NOEND(date))
3022 else
3023 {
3024 /*
3025 * Date's range is wider than timestamp's, so check for boundaries.
3026 * Since dates have the same minimum values as timestamps, only upper
3027 * boundary need be checked for overflow.
3028 */
3030 ereport(ERROR,
3032 errmsg("date out of range for timestamp")));
3033 result = date * USECS_PER_DAY + time->time + time->zone * USECS_PER_SEC;
3034
3035 /*
3036 * Since it is possible to go beyond allowed timestamptz range because
3037 * of time zone, check for allowed timestamp range after adding tz.
3038 */
3040 ereport(ERROR,
3042 errmsg("date out of range for timestamp")));
3043 }
3044
3046}
#define PG_GETARG_TIMETZADT_P(n)
Definition date.h:97
TimeADT time
Definition date.h:27
int32 zone
Definition date.h:28

References DATE_IS_NOBEGIN, DATE_IS_NOEND, ereport, errcode(), errmsg, ERROR, fb(), IS_VALID_TIMESTAMP, PG_GETARG_DATEADT, PG_GETARG_TIMETZADT_P, PG_RETURN_TIMESTAMP, POSTGRES_EPOCH_JDATE, result, TimeTzADT::time, TIMESTAMP_END_JULIAN, TIMESTAMP_NOBEGIN, TIMESTAMP_NOEND, USECS_PER_DAY, USECS_PER_SEC, and TimeTzADT::zone.

◆ EncodeSpecialDate()

void EncodeSpecialDate ( DateADT  dt,
char str 
)

Definition at line 297 of file date.c.

298{
299 if (DATE_IS_NOBEGIN(dt))
300 strcpy(str, EARLY);
301 else if (DATE_IS_NOEND(dt))
302 strcpy(str, LATE);
303 else /* shouldn't happen */
304 elog(ERROR, "invalid argument for EncodeSpecialDate");
305}
#define elog(elevel,...)
Definition elog.h:228
#define EARLY
Definition datetime.h:39
#define LATE
Definition datetime.h:40

References DATE_IS_NOBEGIN, DATE_IS_NOEND, EARLY, elog, ERROR, fb(), LATE, and str.

Referenced by date_out(), and JsonEncodeDateTime().

◆ extract_date()

Datum extract_date ( PG_FUNCTION_ARGS  )

Definition at line 1093 of file date.c.

1094{
1098 int type,
1099 val;
1100 char *lowunits;
1101 int year,
1102 mon,
1103 mday;
1104
1107 false);
1108
1109 type = DecodeUnits(0, lowunits, &val);
1110 if (type == UNKNOWN_FIELD)
1112
1113 if (DATE_NOT_FINITE(date) && (type == UNITS || type == RESERV))
1114 {
1115 switch (val)
1116 {
1117 /* Oscillating units */
1118 case DTK_DAY:
1119 case DTK_MONTH:
1120 case DTK_QUARTER:
1121 case DTK_WEEK:
1122 case DTK_DOW:
1123 case DTK_ISODOW:
1124 case DTK_DOY:
1126 break;
1127
1128 /* Monotonically-increasing units */
1129 case DTK_YEAR:
1130 case DTK_DECADE:
1131 case DTK_CENTURY:
1132 case DTK_MILLENNIUM:
1133 case DTK_JULIAN:
1134 case DTK_ISOYEAR:
1135 case DTK_EPOCH:
1136 if (DATE_IS_NOBEGIN(date))
1138 CStringGetDatum("-Infinity"),
1140 Int32GetDatum(-1))));
1141 else
1143 CStringGetDatum("Infinity"),
1145 Int32GetDatum(-1))));
1146 default:
1147 ereport(ERROR,
1149 errmsg("unit \"%s\" not supported for type %s",
1151 }
1152 }
1153 else if (type == UNITS)
1154 {
1155 j2date(date + POSTGRES_EPOCH_JDATE, &year, &mon, &mday);
1156
1157 switch (val)
1158 {
1159 case DTK_DAY:
1160 intresult = mday;
1161 break;
1162
1163 case DTK_MONTH:
1164 intresult = mon;
1165 break;
1166
1167 case DTK_QUARTER:
1168 intresult = (mon - 1) / 3 + 1;
1169 break;
1170
1171 case DTK_WEEK:
1172 intresult = date2isoweek(year, mon, mday);
1173 break;
1174
1175 case DTK_YEAR:
1176 if (year > 0)
1177 intresult = year;
1178 else
1179 /* there is no year 0, just 1 BC and 1 AD */
1180 intresult = year - 1;
1181 break;
1182
1183 case DTK_DECADE:
1184 /* see comments in timestamp_part */
1185 if (year >= 0)
1186 intresult = year / 10;
1187 else
1188 intresult = -((8 - (year - 1)) / 10);
1189 break;
1190
1191 case DTK_CENTURY:
1192 /* see comments in timestamp_part */
1193 if (year > 0)
1194 intresult = (year + 99) / 100;
1195 else
1196 intresult = -((99 - (year - 1)) / 100);
1197 break;
1198
1199 case DTK_MILLENNIUM:
1200 /* see comments in timestamp_part */
1201 if (year > 0)
1202 intresult = (year + 999) / 1000;
1203 else
1204 intresult = -((999 - (year - 1)) / 1000);
1205 break;
1206
1207 case DTK_JULIAN:
1209 break;
1210
1211 case DTK_ISOYEAR:
1212 intresult = date2isoyear(year, mon, mday);
1213 /* Adjust BC years */
1214 if (intresult <= 0)
1215 intresult -= 1;
1216 break;
1217
1218 case DTK_DOW:
1219 case DTK_ISODOW:
1221 if (val == DTK_ISODOW && intresult == 0)
1222 intresult = 7;
1223 break;
1224
1225 case DTK_DOY:
1226 intresult = date2j(year, mon, mday) - date2j(year, 1, 1) + 1;
1227 break;
1228
1229 default:
1230 ereport(ERROR,
1232 errmsg("unit \"%s\" not supported for type %s",
1234 intresult = 0;
1235 }
1236 }
1237 else if (type == RESERV)
1238 {
1239 switch (val)
1240 {
1241 case DTK_EPOCH:
1243 break;
1244
1245 default:
1246 ereport(ERROR,
1248 errmsg("unit \"%s\" not supported for type %s",
1250 intresult = 0;
1251 }
1252 }
1253 else
1254 {
1255 ereport(ERROR,
1257 errmsg("unit \"%s\" not recognized for type %s",
1259 intresult = 0;
1260 }
1261
1263}
int DecodeUnits(int field, const char *lowtoken, int *val)
Definition datetime.c:4196
int j2day(int date)
Definition datetime.c:355
int DecodeSpecial(int field, const char *lowtoken, int *val)
Definition datetime.c:3266
Numeric int64_to_numeric(int64 val)
Definition numeric.c:4264
Datum numeric_in(PG_FUNCTION_ARGS)
Definition numeric.c:626
int date2isoweek(int year, int mon, int mday)
Definition timestamp.c:5326
int date2isoyear(int year, int mon, int mday)
Definition timestamp.c:5382
#define UNIX_EPOCH_JDATE
Definition timestamp.h:234
#define SECS_PER_DAY
Definition timestamp.h:126
#define PG_GETARG_TEXT_PP(n)
Definition fmgr.h:310
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition fmgr.h:692
char * format_type_be(Oid type_oid)
#define UNKNOWN_FIELD
Definition datetime.h:124
#define DTK_DECADE
Definition datetime.h:168
#define DTK_QUARTER
Definition datetime.h:166
#define DTK_JULIAN
Definition datetime.h:173
#define DTK_CENTURY
Definition datetime.h:169
#define DTK_ISODOW
Definition datetime.h:180
#define DTK_DAY
Definition datetime.h:163
#define RESERV
Definition datetime.h:90
#define DTK_MILLENNIUM
Definition datetime.h:170
#define DTK_ISOYEAR
Definition datetime.h:179
#define DTK_DOY
Definition datetime.h:176
#define DTK_WEEK
Definition datetime.h:164
#define DTK_DOW
Definition datetime.h:175
#define DTK_YEAR
Definition datetime.h:167
#define DTK_MONTH
Definition datetime.h:165
#define UNITS
Definition datetime.h:107
long val
Definition informix.c:689
static Numeric DatumGetNumeric(Datum X)
Definition numeric.h:64
#define PG_RETURN_NUMERIC(x)
Definition numeric.h:83
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
static Datum CStringGetDatum(const char *X)
Definition postgres.h:383
static Datum Int32GetDatum(int32 X)
Definition postgres.h:212
#define InvalidOid
char * downcase_truncate_identifier(const char *ident, int len, bool warn)
Definition scansup.c:38
Definition c.h:776
static Size VARSIZE_ANY_EXHDR(const void *PTR)
Definition varatt.h:472
static char * VARDATA_ANY(const void *PTR)
Definition varatt.h:486
const char * type

References CStringGetDatum(), date2isoweek(), date2isoyear(), date2j(), DATE_IS_NOBEGIN, DATE_NOT_FINITE, DatumGetNumeric(), DecodeSpecial(), DecodeUnits(), DirectFunctionCall3, downcase_truncate_identifier(), DTK_CENTURY, DTK_DAY, DTK_DECADE, DTK_DOW, DTK_DOY, DTK_EPOCH, DTK_ISODOW, DTK_ISOYEAR, DTK_JULIAN, DTK_MILLENNIUM, DTK_MONTH, DTK_QUARTER, DTK_WEEK, DTK_YEAR, ereport, errcode(), errmsg, ERROR, fb(), format_type_be(), Int32GetDatum(), int64_to_numeric(), InvalidOid, j2date(), j2day(), numeric_in(), ObjectIdGetDatum(), PG_GETARG_DATEADT, PG_GETARG_TEXT_PP, PG_RETURN_NULL, PG_RETURN_NUMERIC, POSTGRES_EPOCH_JDATE, RESERV, SECS_PER_DAY, type, UNITS, UNIX_EPOCH_JDATE, UNKNOWN_FIELD, val, VARDATA_ANY(), and VARSIZE_ANY_EXHDR().

◆ extract_time()

Datum extract_time ( PG_FUNCTION_ARGS  )

Definition at line 2367 of file date.c.

2368{
2369 return time_part_common(fcinfo, true);
2370}
static Datum time_part_common(PG_FUNCTION_ARGS, bool retnumeric)
Definition date.c:2258

References time_part_common().

◆ extract_timetz()

Datum extract_timetz ( PG_FUNCTION_ARGS  )

Definition at line 3177 of file date.c.

3178{
3179 return timetz_part_common(fcinfo, true);
3180}
static Datum timetz_part_common(PG_FUNCTION_ARGS, bool retnumeric)
Definition date.c:3054

References timetz_part_common().

◆ float_time_overflows()

bool float_time_overflows ( int  hour,
int  min,
double  sec 
)

Definition at line 1555 of file date.c.

1556{
1557 /* Range-check the fields individually. */
1560 return true;
1561
1562 /*
1563 * "sec", being double, requires extra care. Cope with NaN, and round off
1564 * before applying the range check to avoid unexpected errors due to
1565 * imprecise input. (We assume rint() behaves sanely with infinities.)
1566 */
1567 if (isnan(sec))
1568 return true;
1569 sec = rint(sec * USECS_PER_SEC);
1571 return true;
1572
1573 /*
1574 * Because we allow, eg, hour = 24 or sec = 60, we must check separately
1575 * that the total time value doesn't exceed 24:00:00. This must match the
1576 * way that callers will convert the fields to a time.
1577 */
1578 if (((((hour * MINS_PER_HOUR + min) * SECS_PER_MINUTE)
1579 * USECS_PER_SEC) + (int64) sec) > USECS_PER_DAY)
1580 return true;
1581
1582 return false;
1583}
#define MINS_PER_HOUR
Definition timestamp.h:129
#define SECS_PER_MINUTE
Definition timestamp.h:128
#define HOURS_PER_DAY
Definition timestamp.h:118

References fb(), HOURS_PER_DAY, MINS_PER_HOUR, SECS_PER_MINUTE, USECS_PER_DAY, and USECS_PER_SEC.

Referenced by make_time(), and make_timestamp_internal().

◆ GetSQLCurrentDate()

DateADT GetSQLCurrentDate ( void  )

Definition at line 312 of file date.c.

313{
314 struct pg_tm tm;
315
316 static int cache_year = 0;
317 static int cache_mon = 0;
318 static int cache_mday = 0;
319 static DateADT cache_date;
320
322
323 /*
324 * date2j involves several integer divisions; moreover, unless our session
325 * lives across local midnight, we don't really have to do it more than
326 * once. So it seems worth having a separate cache here.
327 */
328 if (tm.tm_year != cache_year ||
329 tm.tm_mon != cache_mon ||
331 {
336 }
337
338 return cache_date;
339}
void GetCurrentDateTime(struct pg_tm *tm)
Definition datetime.c:377

References date2j(), fb(), GetCurrentDateTime(), POSTGRES_EPOCH_JDATE, tm, pg_tm::tm_mday, pg_tm::tm_mon, and pg_tm::tm_year.

Referenced by ExecEvalSQLValueFunction().

◆ GetSQLCurrentTime()

TimeTzADT * GetSQLCurrentTime ( int32  typmod)

Definition at line 345 of file date.c.

346{
348 struct pg_tm tt,
349 *tm = &tt;
350 fsec_t fsec;
351 int tz;
352
353 GetCurrentTimeUsec(tm, &fsec, &tz);
354
356 tm2timetz(tm, fsec, tz, result);
357 AdjustTimeForTypmod(&(result->time), typmod);
358 return result;
359}
void GetCurrentTimeUsec(struct pg_tm *tm, fsec_t *fsec, int *tzp)
Definition datetime.c:398
int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
Definition date.c:2382
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition date.c:1753
#define palloc_object(type)
Definition fe_memutils.h:89

References AdjustTimeForTypmod(), fb(), GetCurrentTimeUsec(), palloc_object, result, tm, and tm2timetz().

Referenced by ExecEvalSQLValueFunction().

◆ GetSQLLocalTime()

TimeADT GetSQLLocalTime ( int32  typmod)

Definition at line 365 of file date.c.

366{
368 struct pg_tm tt,
369 *tm = &tt;
370 fsec_t fsec;
371 int tz;
372
373 GetCurrentTimeUsec(tm, &fsec, &tz);
374
375 tm2time(tm, fsec, &result);
376 AdjustTimeForTypmod(&result, typmod);
377 return result;
378}
int tm2time(struct pg_tm *tm, fsec_t fsec, TimeADT *result)
Definition date.c:1518

References AdjustTimeForTypmod(), fb(), GetCurrentTimeUsec(), result, tm, and tm2time().

Referenced by ExecEvalSQLValueFunction().

◆ hashdate()

Datum hashdate ( PG_FUNCTION_ARGS  )

Definition at line 507 of file date.c.

508{
510}
static Datum hash_uint32(uint32 k)
Definition hashfn.h:43

References hash_uint32(), and PG_GETARG_DATEADT.

◆ hashdateextended()

Datum hashdateextended ( PG_FUNCTION_ARGS  )

Definition at line 513 of file date.c.

514{
516}
#define PG_GETARG_INT64(n)
Definition fmgr.h:284
static Datum hash_uint32_extended(uint32 k, uint64 seed)
Definition hashfn.h:49

References hash_uint32_extended(), PG_GETARG_DATEADT, and PG_GETARG_INT64.

◆ in_range_date_interval()

Datum in_range_date_interval ( PG_FUNCTION_ARGS  )

Definition at line 1065 of file date.c.

1066{
1068 DateADT base = PG_GETARG_DATEADT(1);
1069 Interval *offset = PG_GETARG_INTERVAL_P(2);
1070 bool sub = PG_GETARG_BOOL(3);
1071 bool less = PG_GETARG_BOOL(4);
1074
1075 /* XXX we could support out-of-range cases here, perhaps */
1077 baseStamp = date2timestamp(base);
1078
1082 IntervalPGetDatum(offset),
1083 BoolGetDatum(sub),
1085}
Datum in_range_timestamp_interval(PG_FUNCTION_ARGS)
Definition timestamp.c:3895
#define PG_GETARG_BOOL(n)
Definition fmgr.h:274
#define DirectFunctionCall5(func, arg1, arg2, arg3, arg4, arg5)
Definition fmgr.h:696
static Datum BoolGetDatum(bool X)
Definition postgres.h:112
static Datum IntervalPGetDatum(const Interval *X)
Definition timestamp.h:58

References BoolGetDatum(), date2timestamp(), DirectFunctionCall5, fb(), in_range_timestamp_interval(), IntervalPGetDatum(), PG_GETARG_BOOL, PG_GETARG_DATEADT, PG_GETARG_INTERVAL_P, TimestampGetDatum(), and val.

◆ in_range_time_interval()

Datum in_range_time_interval ( PG_FUNCTION_ARGS  )

Definition at line 2215 of file date.c.

2216{
2218 TimeADT base = PG_GETARG_TIMEADT(1);
2219 Interval *offset = PG_GETARG_INTERVAL_P(2);
2220 bool sub = PG_GETARG_BOOL(3);
2221 bool less = PG_GETARG_BOOL(4);
2222 TimeADT sum;
2223
2224 /*
2225 * Like time_pl_interval/time_mi_interval, we disregard the month and day
2226 * fields of the offset. So our test for negative should too. This also
2227 * catches -infinity, so we only need worry about +infinity below.
2228 */
2229 if (offset->time < 0)
2230 ereport(ERROR,
2232 errmsg("invalid preceding or following size in window function")));
2233
2234 /*
2235 * We can't use time_pl_interval/time_mi_interval here, because their
2236 * wraparound behavior would give wrong (or at least undesirable) answers.
2237 * Fortunately the equivalent non-wrapping behavior is trivial, except
2238 * that adding an infinite (or very large) interval might cause integer
2239 * overflow. Subtraction cannot overflow here.
2240 */
2241 if (sub)
2242 sum = base - offset->time;
2243 else if (pg_add_s64_overflow(base, offset->time, &sum))
2245
2246 if (less)
2247 PG_RETURN_BOOL(val <= sum);
2248 else
2249 PG_RETURN_BOOL(val >= sum);
2250}
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
Definition int.h:235
TimeOffset time
Definition timestamp.h:49

References ereport, errcode(), errmsg, ERROR, fb(), pg_add_s64_overflow(), PG_GETARG_BOOL, PG_GETARG_INTERVAL_P, PG_GETARG_TIMEADT, PG_RETURN_BOOL, Interval::time, and val.

◆ in_range_timetz_interval()

Datum in_range_timetz_interval ( PG_FUNCTION_ARGS  )

Definition at line 2773 of file date.c.

2774{
2777 Interval *offset = PG_GETARG_INTERVAL_P(2);
2778 bool sub = PG_GETARG_BOOL(3);
2779 bool less = PG_GETARG_BOOL(4);
2780 TimeTzADT sum;
2781
2782 /*
2783 * Like timetz_pl_interval/timetz_mi_interval, we disregard the month and
2784 * day fields of the offset. So our test for negative should too. This
2785 * also catches -infinity, so we only need worry about +infinity below.
2786 */
2787 if (offset->time < 0)
2788 ereport(ERROR,
2790 errmsg("invalid preceding or following size in window function")));
2791
2792 /*
2793 * We can't use timetz_pl_interval/timetz_mi_interval here, because their
2794 * wraparound behavior would give wrong (or at least undesirable) answers.
2795 * Fortunately the equivalent non-wrapping behavior is trivial, except
2796 * that adding an infinite (or very large) interval might cause integer
2797 * overflow. Subtraction cannot overflow here.
2798 */
2799 if (sub)
2800 sum.time = base->time - offset->time;
2801 else if (pg_add_s64_overflow(base->time, offset->time, &sum.time))
2803 sum.zone = base->zone;
2804
2805 if (less)
2807 else
2809}
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition date.c:2564

References ereport, errcode(), errmsg, ERROR, fb(), pg_add_s64_overflow(), PG_GETARG_BOOL, PG_GETARG_INTERVAL_P, PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, Interval::time, TimeTzADT::time, timetz_cmp_internal(), val, and TimeTzADT::zone.

◆ interval_time()

Datum interval_time ( PG_FUNCTION_ARGS  )

Definition at line 2126 of file date.c.

2127{
2130
2132 ereturn(fcinfo->context, (Datum) 0,
2134 errmsg("cannot convert infinite interval to time")));
2135
2136 result = span->time % USECS_PER_DAY;
2137 if (result < 0)
2139
2141}
#define INTERVAL_NOT_FINITE(i)
Definition timestamp.h:195
#define PG_RETURN_TIMEADT(x)
Definition date.h:100

References ereturn, errcode(), errmsg, fb(), INTERVAL_NOT_FINITE, PG_GETARG_INTERVAL_P, PG_RETURN_TIMEADT, result, and USECS_PER_DAY.

◆ make_date()

Datum make_date ( PG_FUNCTION_ARGS  )

Definition at line 241 of file date.c.

242{
243 struct pg_tm tm;
245 int dterr;
246 bool bc = false;
247
251
252 /* Handle negative years as BC */
253 if (tm.tm_year < 0)
254 {
255 int year = tm.tm_year;
256
257 bc = true;
258 if (pg_neg_s32_overflow(year, &year))
261 errmsg("date field value out of range: %d-%02d-%02d",
263 tm.tm_year = year;
264 }
265
266 dterr = ValidateDate(DTK_DATE_M, false, false, bc, &tm);
267
268 if (dterr != 0)
271 errmsg("date field value out of range: %d-%02d-%02d",
273
274 /* Prevent overflow in Julian-day routines */
278 errmsg("date out of range: %d-%02d-%02d",
280
282
283 /* Now check for just-out-of-range dates */
284 if (!IS_VALID_DATE(date))
287 errmsg("date out of range: %d-%02d-%02d",
289
291}
int ValidateDate(int fmask, bool isjulian, bool is2digits, bool bc, struct pg_tm *tm)
Definition datetime.c:2573
#define DTK_DATE_M
Definition datetime.h:191
static bool pg_neg_s32_overflow(int32 a, int32 *result)
Definition int.h:205

References date2j(), DTK_DATE_M, ereport, errcode(), errmsg, ERROR, fb(), IS_VALID_DATE, IS_VALID_JULIAN, PG_GETARG_INT32, pg_neg_s32_overflow(), PG_RETURN_DATEADT, POSTGRES_EPOCH_JDATE, tm, pg_tm::tm_mday, pg_tm::tm_mon, pg_tm::tm_year, and ValidateDate().

◆ make_time()

Datum make_time ( PG_FUNCTION_ARGS  )

Definition at line 1682 of file date.c.

1683{
1684 int tm_hour = PG_GETARG_INT32(0);
1685 int tm_min = PG_GETARG_INT32(1);
1686 double sec = PG_GETARG_FLOAT8(2);
1687 TimeADT time;
1688
1689 /* Check for time overflow */
1690 if (float_time_overflows(tm_hour, tm_min, sec))
1691 ereport(ERROR,
1693 errmsg("time field value out of range: %d:%02d:%02g",
1694 tm_hour, tm_min, sec)));
1695
1696 /* This should match tm2time */
1697 time = (((tm_hour * MINS_PER_HOUR + tm_min) * SECS_PER_MINUTE)
1698 * USECS_PER_SEC) + (int64) rint(sec * USECS_PER_SEC);
1699
1700 PG_RETURN_TIMEADT(time);
1701}
bool float_time_overflows(int hour, int min, double sec)
Definition date.c:1555
#define PG_GETARG_FLOAT8(n)
Definition fmgr.h:283

References ereport, errcode(), errmsg, ERROR, fb(), float_time_overflows(), MINS_PER_HOUR, PG_GETARG_FLOAT8, PG_GETARG_INT32, PG_RETURN_TIMEADT, SECS_PER_MINUTE, pg_tm::tm_hour, pg_tm::tm_min, and USECS_PER_SEC.

◆ overlaps_time()

Datum overlaps_time ( PG_FUNCTION_ARGS  )

Definition at line 1892 of file date.c.

1893{
1894 /*
1895 * The arguments are TimeADT, but we leave them as generic Datums to avoid
1896 * dereferencing nulls (TimeADT is pass-by-reference!)
1897 */
1902 bool ts1IsNull = PG_ARGISNULL(0);
1903 bool te1IsNull = PG_ARGISNULL(1);
1904 bool ts2IsNull = PG_ARGISNULL(2);
1905 bool te2IsNull = PG_ARGISNULL(3);
1906
1907#define TIMEADT_GT(t1,t2) \
1908 (DatumGetTimeADT(t1) > DatumGetTimeADT(t2))
1909#define TIMEADT_LT(t1,t2) \
1910 (DatumGetTimeADT(t1) < DatumGetTimeADT(t2))
1911
1912 /*
1913 * If both endpoints of interval 1 are null, the result is null (unknown).
1914 * If just one endpoint is null, take ts1 as the non-null one. Otherwise,
1915 * take ts1 as the lesser endpoint.
1916 */
1917 if (ts1IsNull)
1918 {
1919 if (te1IsNull)
1921 /* swap null for non-null */
1922 ts1 = te1;
1923 te1IsNull = true;
1924 }
1925 else if (!te1IsNull)
1926 {
1927 if (TIMEADT_GT(ts1, te1))
1928 {
1929 Datum tt = ts1;
1930
1931 ts1 = te1;
1932 te1 = tt;
1933 }
1934 }
1935
1936 /* Likewise for interval 2. */
1937 if (ts2IsNull)
1938 {
1939 if (te2IsNull)
1941 /* swap null for non-null */
1942 ts2 = te2;
1943 te2IsNull = true;
1944 }
1945 else if (!te2IsNull)
1946 {
1947 if (TIMEADT_GT(ts2, te2))
1948 {
1949 Datum tt = ts2;
1950
1951 ts2 = te2;
1952 te2 = tt;
1953 }
1954 }
1955
1956 /*
1957 * At this point neither ts1 nor ts2 is null, so we can consider three
1958 * cases: ts1 > ts2, ts1 < ts2, ts1 = ts2
1959 */
1960 if (TIMEADT_GT(ts1, ts2))
1961 {
1962 /*
1963 * This case is ts1 < te2 OR te1 < te2, which may look redundant but
1964 * in the presence of nulls it's not quite completely so.
1965 */
1966 if (te2IsNull)
1968 if (TIMEADT_LT(ts1, te2))
1969 PG_RETURN_BOOL(true);
1970 if (te1IsNull)
1972
1973 /*
1974 * If te1 is not null then we had ts1 <= te1 above, and we just found
1975 * ts1 >= te2, hence te1 >= te2.
1976 */
1977 PG_RETURN_BOOL(false);
1978 }
1979 else if (TIMEADT_LT(ts1, ts2))
1980 {
1981 /* This case is ts2 < te1 OR te2 < te1 */
1982 if (te1IsNull)
1984 if (TIMEADT_LT(ts2, te1))
1985 PG_RETURN_BOOL(true);
1986 if (te2IsNull)
1988
1989 /*
1990 * If te2 is not null then we had ts2 <= te2 above, and we just found
1991 * ts2 >= te1, hence te2 >= te1.
1992 */
1993 PG_RETURN_BOOL(false);
1994 }
1995 else
1996 {
1997 /*
1998 * For ts1 = ts2 the spec says te1 <> te2 OR te1 = te2, which is a
1999 * rather silly way of saying "true if both are nonnull, else null".
2000 */
2001 if (te1IsNull || te2IsNull)
2003 PG_RETURN_BOOL(true);
2004 }
2005
2006#undef TIMEADT_GT
2007#undef TIMEADT_LT
2008}
#define TIMEADT_GT(t1, t2)
#define TIMEADT_LT(t1, t2)
#define PG_ARGISNULL(n)
Definition fmgr.h:209
#define PG_GETARG_DATUM(n)
Definition fmgr.h:268

References fb(), PG_ARGISNULL, PG_GETARG_DATUM, PG_RETURN_BOOL, PG_RETURN_NULL, TIMEADT_GT, and TIMEADT_LT.

◆ overlaps_timetz()

Datum overlaps_timetz ( PG_FUNCTION_ARGS  )

Definition at line 2819 of file date.c.

2820{
2821 /*
2822 * The arguments are TimeTzADT *, but we leave them as generic Datums for
2823 * convenience of notation --- and to avoid dereferencing nulls.
2824 */
2829 bool ts1IsNull = PG_ARGISNULL(0);
2830 bool te1IsNull = PG_ARGISNULL(1);
2831 bool ts2IsNull = PG_ARGISNULL(2);
2832 bool te2IsNull = PG_ARGISNULL(3);
2833
2834#define TIMETZ_GT(t1,t2) \
2835 DatumGetBool(DirectFunctionCall2(timetz_gt,t1,t2))
2836#define TIMETZ_LT(t1,t2) \
2837 DatumGetBool(DirectFunctionCall2(timetz_lt,t1,t2))
2838
2839 /*
2840 * If both endpoints of interval 1 are null, the result is null (unknown).
2841 * If just one endpoint is null, take ts1 as the non-null one. Otherwise,
2842 * take ts1 as the lesser endpoint.
2843 */
2844 if (ts1IsNull)
2845 {
2846 if (te1IsNull)
2848 /* swap null for non-null */
2849 ts1 = te1;
2850 te1IsNull = true;
2851 }
2852 else if (!te1IsNull)
2853 {
2854 if (TIMETZ_GT(ts1, te1))
2855 {
2856 Datum tt = ts1;
2857
2858 ts1 = te1;
2859 te1 = tt;
2860 }
2861 }
2862
2863 /* Likewise for interval 2. */
2864 if (ts2IsNull)
2865 {
2866 if (te2IsNull)
2868 /* swap null for non-null */
2869 ts2 = te2;
2870 te2IsNull = true;
2871 }
2872 else if (!te2IsNull)
2873 {
2874 if (TIMETZ_GT(ts2, te2))
2875 {
2876 Datum tt = ts2;
2877
2878 ts2 = te2;
2879 te2 = tt;
2880 }
2881 }
2882
2883 /*
2884 * At this point neither ts1 nor ts2 is null, so we can consider three
2885 * cases: ts1 > ts2, ts1 < ts2, ts1 = ts2
2886 */
2887 if (TIMETZ_GT(ts1, ts2))
2888 {
2889 /*
2890 * This case is ts1 < te2 OR te1 < te2, which may look redundant but
2891 * in the presence of nulls it's not quite completely so.
2892 */
2893 if (te2IsNull)
2895 if (TIMETZ_LT(ts1, te2))
2896 PG_RETURN_BOOL(true);
2897 if (te1IsNull)
2899
2900 /*
2901 * If te1 is not null then we had ts1 <= te1 above, and we just found
2902 * ts1 >= te2, hence te1 >= te2.
2903 */
2904 PG_RETURN_BOOL(false);
2905 }
2906 else if (TIMETZ_LT(ts1, ts2))
2907 {
2908 /* This case is ts2 < te1 OR te2 < te1 */
2909 if (te1IsNull)
2911 if (TIMETZ_LT(ts2, te1))
2912 PG_RETURN_BOOL(true);
2913 if (te2IsNull)
2915
2916 /*
2917 * If te2 is not null then we had ts2 <= te2 above, and we just found
2918 * ts2 >= te1, hence te2 >= te1.
2919 */
2920 PG_RETURN_BOOL(false);
2921 }
2922 else
2923 {
2924 /*
2925 * For ts1 = ts2 the spec says te1 <> te2 OR te1 = te2, which is a
2926 * rather silly way of saying "true if both are nonnull, else null".
2927 */
2928 if (te1IsNull || te2IsNull)
2930 PG_RETURN_BOOL(true);
2931 }
2932
2933#undef TIMETZ_GT
2934#undef TIMETZ_LT
2935}
#define TIMETZ_GT(t1, t2)
#define TIMETZ_LT(t1, t2)

References fb(), PG_ARGISNULL, PG_GETARG_DATUM, PG_RETURN_BOOL, PG_RETURN_NULL, TIMETZ_GT, and TIMETZ_LT.

◆ time2tm()

int time2tm ( TimeADT  time,
struct pg_tm tm,
fsec_t fsec 
)

Definition at line 1593 of file date.c.

1594{
1595 tm->tm_hour = time / USECS_PER_HOUR;
1596 time -= tm->tm_hour * USECS_PER_HOUR;
1597 tm->tm_min = time / USECS_PER_MINUTE;
1598 time -= tm->tm_min * USECS_PER_MINUTE;
1599 tm->tm_sec = time / USECS_PER_SEC;
1600 time -= tm->tm_sec * USECS_PER_SEC;
1601 *fsec = time;
1602 return 0;
1603}
#define USECS_PER_HOUR
Definition timestamp.h:132
#define USECS_PER_MINUTE
Definition timestamp.h:133

References tm, pg_tm::tm_hour, pg_tm::tm_min, pg_tm::tm_sec, USECS_PER_HOUR, USECS_PER_MINUTE, and USECS_PER_SEC.

Referenced by JsonEncodeDateTime(), time_out(), time_part_common(), and time_timetz().

◆ time_cmp()

Datum time_cmp ( PG_FUNCTION_ARGS  )

Definition at line 1842 of file date.c.

1843{
1846
1847 if (time1 < time2)
1848 PG_RETURN_INT32(-1);
1849 if (time1 > time2)
1850 PG_RETURN_INT32(1);
1851 PG_RETURN_INT32(0);
1852}

References fb(), PG_GETARG_TIMEADT, and PG_RETURN_INT32.

Referenced by compareDatetime(), gbt_timekey_cmp(), and gbt_timekey_ssup_cmp().

◆ time_eq()

Datum time_eq ( PG_FUNCTION_ARGS  )

Definition at line 1788 of file date.c.

1789{
1792
1794}

References fb(), PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timeeq().

◆ time_ge()

Datum time_ge ( PG_FUNCTION_ARGS  )

Definition at line 1833 of file date.c.

1834{
1837
1839}

References fb(), PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timege().

◆ time_gt()

Datum time_gt ( PG_FUNCTION_ARGS  )

Definition at line 1824 of file date.c.

1825{
1828
1830}

References fb(), PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timegt().

◆ time_hash()

Datum time_hash ( PG_FUNCTION_ARGS  )

Definition at line 1855 of file date.c.

1856{
1857 return hashint8(fcinfo);
1858}
Datum hashint8(PG_FUNCTION_ARGS)
Definition hashfunc.c:84

References hashint8().

◆ time_hash_extended()

Datum time_hash_extended ( PG_FUNCTION_ARGS  )

Definition at line 1861 of file date.c.

1862{
1863 return hashint8extended(fcinfo);
1864}
Datum hashint8extended(PG_FUNCTION_ARGS)
Definition hashfunc.c:104

References hashint8extended().

◆ time_in()

Datum time_in ( PG_FUNCTION_ARGS  )

Definition at line 1475 of file date.c.

1476{
1477 char *str = PG_GETARG_CSTRING(0);
1478#ifdef NOT_USED
1479 Oid typelem = PG_GETARG_OID(1);
1480#endif
1481 int32 typmod = PG_GETARG_INT32(2);
1482 Node *escontext = fcinfo->context;
1484 fsec_t fsec;
1485 struct pg_tm tt,
1486 *tm = &tt;
1487 int tz;
1488 int nf;
1489 int dterr;
1490 char workbuf[MAXDATELEN + 1];
1491 char *field[MAXDATEFIELDS];
1492 int dtype;
1493 int ftype[MAXDATEFIELDS];
1494 DateTimeErrorExtra extra;
1495
1497 field, ftype, MAXDATEFIELDS, &nf);
1498 if (dterr == 0)
1499 dterr = DecodeTimeOnly(field, ftype, nf,
1500 &dtype, tm, &fsec, &tz, &extra);
1501 if (dterr != 0)
1502 {
1503 DateTimeParseError(dterr, &extra, str, "time", escontext);
1505 }
1506
1507 tm2time(tm, fsec, &result);
1508 AdjustTimeForTypmod(&result, typmod);
1509
1511}
int DecodeTimeOnly(char **field, int *ftype, int nf, int *dtype, struct pg_tm *tm, fsec_t *fsec, int *tzp, DateTimeErrorExtra *extra)
Definition datetime.c:1927
#define PG_GETARG_OID(n)
Definition fmgr.h:275
unsigned int Oid

References AdjustTimeForTypmod(), DateTimeParseError(), DecodeTimeOnly(), fb(), MAXDATEFIELDS, MAXDATELEN, ParseDateTime(), PG_GETARG_CSTRING, PG_GETARG_INT32, PG_GETARG_OID, PG_RETURN_NULL, PG_RETURN_TIMEADT, result, str, tm, and tm2time().

◆ time_interval()

Datum time_interval ( PG_FUNCTION_ARGS  )

Definition at line 2102 of file date.c.

2103{
2104 TimeADT time = PG_GETARG_TIMEADT(0);
2106
2108
2109 result->time = time;
2110 result->day = 0;
2111 result->month = 0;
2112
2114}
#define PG_RETURN_INTERVAL_P(x)
Definition timestamp.h:69

References palloc_object, PG_GETARG_TIMEADT, PG_RETURN_INTERVAL_P, and result.

◆ time_larger()

Datum time_larger ( PG_FUNCTION_ARGS  )

Definition at line 1867 of file date.c.

1868{
1871
1873}

References fb(), PG_GETARG_TIMEADT, and PG_RETURN_TIMEADT.

◆ time_le()

Datum time_le ( PG_FUNCTION_ARGS  )

Definition at line 1815 of file date.c.

1816{
1819
1821}

References fb(), PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timele().

◆ time_lt()

Datum time_lt ( PG_FUNCTION_ARGS  )

Definition at line 1806 of file date.c.

1807{
1810
1812}

References fb(), PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timelt().

◆ time_mi_interval()

Datum time_mi_interval ( PG_FUNCTION_ARGS  )

Definition at line 2192 of file date.c.

2193{
2194 TimeADT time = PG_GETARG_TIMEADT(0);
2197
2199 ereport(ERROR,
2201 errmsg("cannot subtract infinite interval from time")));
2202
2203 result = time - span->time;
2205 if (result < INT64CONST(0))
2207
2209}

References ereport, errcode(), errmsg, ERROR, fb(), INT64CONST, INTERVAL_NOT_FINITE, PG_GETARG_INTERVAL_P, PG_GETARG_TIMEADT, PG_RETURN_TIMEADT, result, and USECS_PER_DAY.

◆ time_mi_time()

Datum time_mi_time ( PG_FUNCTION_ARGS  )

Definition at line 2148 of file date.c.

2149{
2153
2155
2156 result->month = 0;
2157 result->day = 0;
2158 result->time = time1 - time2;
2159
2161}

References fb(), palloc_object, PG_GETARG_TIMEADT, PG_RETURN_INTERVAL_P, and result.

Referenced by gbt_time_dist(), gbt_time_penalty(), and time_dist().

◆ time_ne()

Datum time_ne ( PG_FUNCTION_ARGS  )

Definition at line 1797 of file date.c.

1798{
1801
1803}

References fb(), PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

◆ time_out()

Datum time_out ( PG_FUNCTION_ARGS  )

Definition at line 1606 of file date.c.

1607{
1608 TimeADT time = PG_GETARG_TIMEADT(0);
1609 char *result;
1610 struct pg_tm tt,
1611 *tm = &tt;
1612 fsec_t fsec;
1613 char buf[MAXDATELEN + 1];
1614
1615 time2tm(time, tm, &fsec);
1616 EncodeTimeOnly(tm, fsec, false, 0, DateStyle, buf);
1617
1618 result = pstrdup(buf);
1620}
void EncodeTimeOnly(struct pg_tm *tm, fsec_t fsec, bool print_tz, int tz, int style, char *str)
Definition datetime.c:4465
int time2tm(TimeADT time, struct pg_tm *tm, fsec_t *fsec)
Definition date.c:1593

References buf, DateStyle, EncodeTimeOnly(), fb(), MAXDATELEN, PG_GETARG_TIMEADT, PG_RETURN_CSTRING, pstrdup(), result, time2tm(), and tm.

Referenced by ExecGetJsonValueItemString().

◆ time_overflows()

bool time_overflows ( int  hour,
int  min,
int  sec,
fsec_t  fsec 
)

Definition at line 1530 of file date.c.

1531{
1532 /* Range-check the fields individually. */
1537 return true;
1538
1539 /*
1540 * Because we allow, eg, hour = 24 or sec = 60, we must check separately
1541 * that the total time value doesn't exceed 24:00:00.
1542 */
1543 if ((((((hour * MINS_PER_HOUR + min) * SECS_PER_MINUTE)
1544 + sec) * USECS_PER_SEC) + fsec) > USECS_PER_DAY)
1545 return true;
1546
1547 return false;
1548}

References fb(), HOURS_PER_DAY, MINS_PER_HOUR, SECS_PER_MINUTE, USECS_PER_DAY, and USECS_PER_SEC.

Referenced by DecodeDateTime(), and DecodeTimeOnly().

◆ time_part()

Datum time_part ( PG_FUNCTION_ARGS  )

Definition at line 2361 of file date.c.

2362{
2363 return time_part_common(fcinfo, false);
2364}

References time_part_common().

◆ time_part_common()

static Datum time_part_common ( PG_FUNCTION_ARGS  ,
bool  retnumeric 
)
static

Definition at line 2258 of file date.c.

2259{
2261 TimeADT time = PG_GETARG_TIMEADT(1);
2263 int type,
2264 val;
2265 char *lowunits;
2266
2269 false);
2270
2271 type = DecodeUnits(0, lowunits, &val);
2272 if (type == UNKNOWN_FIELD)
2274
2275 if (type == UNITS)
2276 {
2277 fsec_t fsec;
2278 struct pg_tm tt,
2279 *tm = &tt;
2280
2281 time2tm(time, tm, &fsec);
2282
2283 switch (val)
2284 {
2285 case DTK_MICROSEC:
2286 intresult = tm->tm_sec * INT64CONST(1000000) + fsec;
2287 break;
2288
2289 case DTK_MILLISEC:
2290 if (retnumeric)
2291 /*---
2292 * tm->tm_sec * 1000 + fsec / 1000
2293 * = (tm->tm_sec * 1'000'000 + fsec) / 1000
2294 */
2296 else
2297 PG_RETURN_FLOAT8(tm->tm_sec * 1000.0 + fsec / 1000.0);
2298 break;
2299
2300 case DTK_SECOND:
2301 if (retnumeric)
2302 /*---
2303 * tm->tm_sec + fsec / 1'000'000
2304 * = (tm->tm_sec * 1'000'000 + fsec) / 1'000'000
2305 */
2307 else
2308 PG_RETURN_FLOAT8(tm->tm_sec + fsec / 1000000.0);
2309 break;
2310
2311 case DTK_MINUTE:
2312 intresult = tm->tm_min;
2313 break;
2314
2315 case DTK_HOUR:
2316 intresult = tm->tm_hour;
2317 break;
2318
2319 case DTK_TZ:
2320 case DTK_TZ_MINUTE:
2321 case DTK_TZ_HOUR:
2322 case DTK_DAY:
2323 case DTK_MONTH:
2324 case DTK_QUARTER:
2325 case DTK_YEAR:
2326 case DTK_DECADE:
2327 case DTK_CENTURY:
2328 case DTK_MILLENNIUM:
2329 case DTK_ISOYEAR:
2330 default:
2331 ereport(ERROR,
2333 errmsg("unit \"%s\" not supported for type %s",
2335 intresult = 0;
2336 }
2337 }
2338 else if (type == RESERV && val == DTK_EPOCH)
2339 {
2340 if (retnumeric)
2342 else
2343 PG_RETURN_FLOAT8(time / 1000000.0);
2344 }
2345 else
2346 {
2347 ereport(ERROR,
2349 errmsg("unit \"%s\" not recognized for type %s",
2351 intresult = 0;
2352 }
2353
2354 if (retnumeric)
2356 else
2358}
Numeric int64_div_fast_to_numeric(int64 val1, int log10val2)
Definition numeric.c:4285
#define PG_RETURN_FLOAT8(x)
Definition fmgr.h:369
#define DTK_SECOND
Definition datetime.h:160
#define DTK_TZ_HOUR
Definition datetime.h:177
#define DTK_TZ_MINUTE
Definition datetime.h:178
#define DTK_TZ
Definition datetime.h:146
#define DTK_HOUR
Definition datetime.h:162
#define DTK_MICROSEC
Definition datetime.h:172
#define DTK_MILLISEC
Definition datetime.h:171
#define DTK_MINUTE
Definition datetime.h:161

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, fb(), format_type_be(), int64_div_fast_to_numeric(), int64_to_numeric(), INT64CONST, PG_GETARG_TEXT_PP, PG_GETARG_TIMEADT, PG_RETURN_FLOAT8, PG_RETURN_NUMERIC, RESERV, time2tm(), tm, pg_tm::tm_hour, pg_tm::tm_min, pg_tm::tm_sec, type, UNITS, UNKNOWN_FIELD, val, VARDATA_ANY(), and VARSIZE_ANY_EXHDR().

Referenced by extract_time(), and time_part().

◆ time_pl_interval()

Datum time_pl_interval ( PG_FUNCTION_ARGS  )

Definition at line 2168 of file date.c.

2169{
2170 TimeADT time = PG_GETARG_TIMEADT(0);
2173
2175 ereport(ERROR,
2177 errmsg("cannot add infinite interval to time")));
2178
2179 result = time + span->time;
2181 if (result < INT64CONST(0))
2183
2185}

References ereport, errcode(), errmsg, ERROR, fb(), INT64CONST, INTERVAL_NOT_FINITE, PG_GETARG_INTERVAL_P, PG_GETARG_TIMEADT, PG_RETURN_TIMEADT, result, and USECS_PER_DAY.

◆ time_recv()

Datum time_recv ( PG_FUNCTION_ARGS  )

Definition at line 1626 of file date.c.

1627{
1629
1630#ifdef NOT_USED
1631 Oid typelem = PG_GETARG_OID(1);
1632#endif
1633 int32 typmod = PG_GETARG_INT32(2);
1635
1637
1638 if (result < INT64CONST(0) || result > USECS_PER_DAY)
1639 ereport(ERROR,
1641 errmsg("time out of range")));
1642
1643 AdjustTimeForTypmod(&result, typmod);
1644
1646}
int64 pq_getmsgint64(StringInfo msg)
Definition pqformat.c:452

References AdjustTimeForTypmod(), buf, ereport, errcode(), errmsg, ERROR, fb(), INT64CONST, PG_GETARG_INT32, PG_GETARG_OID, PG_GETARG_POINTER, PG_RETURN_TIMEADT, pq_getmsgint64(), result, and USECS_PER_DAY.

◆ time_scale()

Datum time_scale ( PG_FUNCTION_ARGS  )

Definition at line 1732 of file date.c.

1733{
1734 TimeADT time = PG_GETARG_TIMEADT(0);
1735 int32 typmod = PG_GETARG_INT32(1);
1737
1738 result = time;
1739 AdjustTimeForTypmod(&result, typmod);
1740
1742}

References AdjustTimeForTypmod(), PG_GETARG_INT32, PG_GETARG_TIMEADT, PG_RETURN_TIMEADT, and result.

◆ time_send()

Datum time_send ( PG_FUNCTION_ARGS  )

Definition at line 1652 of file date.c.

1653{
1654 TimeADT time = PG_GETARG_TIMEADT(0);
1656
1658 pq_sendint64(&buf, time);
1660}
static void pq_sendint64(StringInfo buf, uint64 i)
Definition pqformat.h:152

References buf, PG_GETARG_TIMEADT, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint64().

◆ time_smaller()

Datum time_smaller ( PG_FUNCTION_ARGS  )

Definition at line 1876 of file date.c.

1877{
1880
1882}

References fb(), PG_GETARG_TIMEADT, and PG_RETURN_TIMEADT.

◆ time_support()

Datum time_support ( PG_FUNCTION_ARGS  )

Definition at line 1711 of file date.c.

1712{
1714 Node *ret = NULL;
1715
1717 {
1719
1720 ret = TemporalSimplify(MAX_TIME_PRECISION, (Node *) req->fcall);
1721 }
1722
1723 PG_RETURN_POINTER(ret);
1724}
Node * TemporalSimplify(int32 max_precis, Node *node)
Definition datetime.c:4995
#define PG_RETURN_POINTER(x)
Definition fmgr.h:363
#define IsA(nodeptr, _type_)
Definition nodes.h:164

References fb(), IsA, MAX_TIME_PRECISION, PG_GETARG_POINTER, PG_RETURN_POINTER, and TemporalSimplify().

◆ time_timetz()

Datum time_timetz ( PG_FUNCTION_ARGS  )

Definition at line 2952 of file date.c.

2953{
2954 TimeADT time = PG_GETARG_TIMEADT(0);
2956 struct pg_tm tt,
2957 *tm = &tt;
2958 fsec_t fsec;
2959 int tz;
2960
2962 time2tm(time, tm, &fsec);
2964
2966
2967 result->time = time;
2968 result->zone = tz;
2969
2971}
#define PG_RETURN_TIMETZADT_P(x)
Definition date.h:101

References DetermineTimeZoneOffset(), fb(), GetCurrentDateTime(), palloc_object, PG_GETARG_TIMEADT, PG_RETURN_TIMETZADT_P, result, session_timezone, time2tm(), and tm.

Referenced by castTimeToTimeTz(), and executeDateTimeMethod().

◆ timestamp2date_safe()

DateADT timestamp2date_safe ( Timestamp  timestamp,
Node escontext 
)

Definition at line 1356 of file date.c.

1357{
1359 struct pg_tm tt,
1360 *tm = &tt;
1361 fsec_t fsec;
1362
1365 else if (TIMESTAMP_IS_NOEND(timestamp))
1367 else
1368 {
1369 if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
1370 {
1371 if (timestamp < 0)
1373 else
1374 DATE_NOEND(result); /* not actually reachable */
1375
1376 ereturn(escontext, result,
1378 errmsg("timestamp out of range")));
1379 }
1380
1382 }
1383
1384 return result;
1385}
int timestamp2tm(Timestamp dt, int *tzp, struct pg_tm *tm, fsec_t *fsec, const char **tzn, pg_tz *attimezone)
Definition timestamp.c:1918
int64 timestamp

References date2j(), DATE_NOBEGIN, DATE_NOEND, ereturn, errcode(), errmsg, fb(), POSTGRES_EPOCH_JDATE, result, timestamp2tm(), TIMESTAMP_IS_NOBEGIN, TIMESTAMP_IS_NOEND, tm, pg_tm::tm_mday, pg_tm::tm_mon, and pg_tm::tm_year.

Referenced by cvt_timestamp_date(), and timestamp_date().

◆ timestamp_cmp_date()

◆ timestamp_date()

Datum timestamp_date ( PG_FUNCTION_ARGS  )

Definition at line 1330 of file date.c.

1331{
1334
1335 result = timestamp2date_safe(timestamp, fcinfo->context);
1336 if (SOFT_ERROR_OCCURRED(fcinfo->context))
1338
1340}
DateADT timestamp2date_safe(Timestamp timestamp, Node *escontext)
Definition date.c:1356

References PG_GETARG_TIMESTAMP, PG_RETURN_DATEADT, PG_RETURN_NULL, result, SOFT_ERROR_OCCURRED, and timestamp2date_safe().

Referenced by executeDateTimeMethod().

◆ timestamp_eq_date()

◆ timestamp_ge_date()

◆ timestamp_gt_date()

◆ timestamp_le_date()

◆ timestamp_lt_date()

◆ timestamp_ne_date()

◆ timestamp_time()

Datum timestamp_time ( PG_FUNCTION_ARGS  )

Definition at line 2015 of file date.c.

2016{
2019 struct pg_tm tt,
2020 *tm = &tt;
2021 fsec_t fsec;
2022
2025
2026 if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
2027 ereturn(fcinfo->context, (Datum) 0,
2029 errmsg("timestamp out of range")));
2030
2031 /*
2032 * Could also do this with time = (timestamp / USECS_PER_DAY *
2033 * USECS_PER_DAY) - timestamp;
2034 */
2036 USECS_PER_SEC) + fsec;
2037
2039}

References ereturn, errcode(), errmsg, fb(), MINS_PER_HOUR, PG_GETARG_TIMESTAMP, PG_RETURN_NULL, PG_RETURN_TIMEADT, result, SECS_PER_MINUTE, timestamp2tm(), TIMESTAMP_NOT_FINITE, tm, pg_tm::tm_hour, pg_tm::tm_min, pg_tm::tm_sec, and USECS_PER_SEC.

Referenced by executeDateTimeMethod().

◆ timestamptz2date_safe()

DateADT timestamptz2date_safe ( TimestampTz  timestamp,
Node escontext 
)

Definition at line 1437 of file date.c.

1438{
1440 struct pg_tm tt,
1441 *tm = &tt;
1442 fsec_t fsec;
1443 int tz;
1444
1447 else if (TIMESTAMP_IS_NOEND(timestamp))
1449 else
1450 {
1451 if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
1452 {
1453 if (timestamp < 0)
1455 else
1456 DATE_NOEND(result); /* not actually reachable */
1457
1458 ereturn(escontext, result,
1460 errmsg("timestamp out of range")));
1461 }
1462
1464 }
1465
1466 return result;
1467}

References date2j(), DATE_NOBEGIN, DATE_NOEND, ereturn, errcode(), errmsg, fb(), POSTGRES_EPOCH_JDATE, result, timestamp2tm(), TIMESTAMP_IS_NOBEGIN, TIMESTAMP_IS_NOEND, tm, pg_tm::tm_mday, pg_tm::tm_mon, and pg_tm::tm_year.

Referenced by cvt_timestamptz_date(), and timestamptz_date().

◆ timestamptz_cmp_date()

◆ timestamptz_date()

Datum timestamptz_date ( PG_FUNCTION_ARGS  )

Definition at line 1411 of file date.c.

1412{
1415
1416 result = timestamptz2date_safe(timestamp, fcinfo->context);
1417 if (SOFT_ERROR_OCCURRED(fcinfo->context))
1419
1421}
DateADT timestamptz2date_safe(TimestampTz timestamp, Node *escontext)
Definition date.c:1437

References PG_GETARG_TIMESTAMP, PG_RETURN_DATEADT, PG_RETURN_NULL, result, SOFT_ERROR_OCCURRED, and timestamptz2date_safe().

Referenced by executeDateTimeMethod().

◆ timestamptz_eq_date()

◆ timestamptz_ge_date()

◆ timestamptz_gt_date()

◆ timestamptz_le_date()

◆ timestamptz_lt_date()

◆ timestamptz_ne_date()

◆ timestamptz_time()

Datum timestamptz_time ( PG_FUNCTION_ARGS  )

Definition at line 2046 of file date.c.

2047{
2050 struct pg_tm tt,
2051 *tm = &tt;
2052 int tz;
2053 fsec_t fsec;
2054
2057
2058 if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
2059 ereturn(fcinfo->context, (Datum) 0,
2061 errmsg("timestamp out of range")));
2062
2063 /*
2064 * Could also do this with time = (timestamp / USECS_PER_DAY *
2065 * USECS_PER_DAY) - timestamp;
2066 */
2068 USECS_PER_SEC) + fsec;
2069
2071}

References ereturn, errcode(), errmsg, fb(), MINS_PER_HOUR, PG_GETARG_TIMESTAMP, PG_RETURN_NULL, PG_RETURN_TIMEADT, result, SECS_PER_MINUTE, timestamp2tm(), TIMESTAMP_NOT_FINITE, tm, pg_tm::tm_hour, pg_tm::tm_min, pg_tm::tm_sec, and USECS_PER_SEC.

Referenced by executeDateTimeMethod().

◆ timestamptz_timetz()

Datum timestamptz_timetz ( PG_FUNCTION_ARGS  )

Definition at line 2979 of file date.c.

2980{
2983 struct pg_tm tt,
2984 *tm = &tt;
2985 int tz;
2986 fsec_t fsec;
2987
2990
2991 if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
2992 ereturn(fcinfo->context, (Datum) 0,
2994 errmsg("timestamp out of range")));
2995
2997
2998 tm2timetz(tm, fsec, tz, result);
2999
3001}

References ereturn, errcode(), errmsg, fb(), palloc_object, PG_GETARG_TIMESTAMP, PG_RETURN_NULL, PG_RETURN_TIMETZADT_P, result, timestamp2tm(), TIMESTAMP_NOT_FINITE, tm, and tm2timetz().

Referenced by executeDateTimeMethod().

◆ timetypmodin()

Datum timetypmodin ( PG_FUNCTION_ARGS  )

Definition at line 1663 of file date.c.

1664{
1666
1668}
#define PG_GETARG_ARRAYTYPE_P(n)
Definition array.h:263
static int32 anytime_typmodin(bool istz, ArrayType *ta)
Definition date.c:44

References anytime_typmodin(), fb(), PG_GETARG_ARRAYTYPE_P, and PG_RETURN_INT32.

◆ timetypmodout()

Datum timetypmodout ( PG_FUNCTION_ARGS  )

Definition at line 1671 of file date.c.

1672{
1673 int32 typmod = PG_GETARG_INT32(0);
1674
1675 PG_RETURN_CSTRING(anytime_typmodout(false, typmod));
1676}
static char * anytime_typmodout(bool istz, int32 typmod)
Definition date.c:87

References anytime_typmodout(), PG_GETARG_INT32, and PG_RETURN_CSTRING.

◆ timetz2tm()

int timetz2tm ( TimeTzADT time,
struct pg_tm tm,
fsec_t fsec,
int tzp 
)

Definition at line 2523 of file date.c.

2524{
2525 TimeOffset trem = time->time;
2526
2532 *fsec = trem - tm->tm_sec * USECS_PER_SEC;
2533
2534 if (tzp != NULL)
2535 *tzp = time->zone;
2536
2537 return 0;
2538}
int64 TimeOffset
Definition timestamp.h:40

References fb(), TimeTzADT::time, tm, pg_tm::tm_hour, pg_tm::tm_min, pg_tm::tm_sec, USECS_PER_HOUR, USECS_PER_MINUTE, USECS_PER_SEC, and TimeTzADT::zone.

Referenced by JsonEncodeDateTime(), timetz_out(), and timetz_part_common().

◆ timetz_at_local()

Datum timetz_at_local ( PG_FUNCTION_ARGS  )

Definition at line 3295 of file date.c.

3296{
3297 Datum time = PG_GETARG_DATUM(0);
3298 const char *tzn = pg_get_timezone_name(session_timezone);
3300
3301 return DirectFunctionCall2(timetz_zone, zone, time);
3302}
Datum timetz_zone(PG_FUNCTION_ARGS)
Definition date.c:3188
const char * pg_get_timezone_name(pg_tz *tz)
Definition localtime.c:1992
Definition zic.c:101
text * cstring_to_text(const char *s)
Definition varlena.c:184

References cstring_to_text(), DirectFunctionCall2, pg_get_timezone_name(), PG_GETARG_DATUM, PointerGetDatum, session_timezone, and timetz_zone().

◆ timetz_cmp()

Datum timetz_cmp ( PG_FUNCTION_ARGS  )

◆ timetz_cmp_internal()

static int timetz_cmp_internal ( TimeTzADT time1,
TimeTzADT time2 
)
static

Definition at line 2564 of file date.c.

2565{
2566 TimeOffset t1,
2567 t2;
2568
2569 /* Primary sort is by true (GMT-equivalent) time */
2570 t1 = time1->time + (time1->zone * USECS_PER_SEC);
2571 t2 = time2->time + (time2->zone * USECS_PER_SEC);
2572
2573 if (t1 > t2)
2574 return 1;
2575 if (t1 < t2)
2576 return -1;
2577
2578 /*
2579 * If same GMT time, sort by timezone; we only want to say that two
2580 * timetz's are equal if both the time and zone parts are equal.
2581 */
2582 if (time1->zone > time2->zone)
2583 return 1;
2584 if (time1->zone < time2->zone)
2585 return -1;
2586
2587 return 0;
2588}

References fb(), and USECS_PER_SEC.

Referenced by in_range_timetz_interval(), timetz_cmp(), timetz_eq(), timetz_ge(), timetz_gt(), timetz_larger(), timetz_le(), timetz_lt(), timetz_ne(), and timetz_smaller().

◆ timetz_eq()

Datum timetz_eq ( PG_FUNCTION_ARGS  )

◆ timetz_ge()

Datum timetz_ge ( PG_FUNCTION_ARGS  )

◆ timetz_gt()

Datum timetz_gt ( PG_FUNCTION_ARGS  )

◆ timetz_hash()

Datum timetz_hash ( PG_FUNCTION_ARGS  )

Definition at line 2654 of file date.c.

2655{
2657 uint32 thash;
2658
2659 /*
2660 * To avoid any problems with padding bytes in the struct, we figure the
2661 * field hashes separately and XOR them.
2662 */
2664 Int64GetDatumFast(key->time)));
2667}
uint32_t uint32
Definition c.h:624
#define PG_RETURN_UINT32(x)
Definition fmgr.h:356
#define DirectFunctionCall1(func, arg1)
Definition fmgr.h:688
static uint32 DatumGetUInt32(Datum X)
Definition postgres.h:222
#define Int64GetDatumFast(X)
Definition postgres.h:538

References DatumGetUInt32(), DirectFunctionCall1, fb(), hash_uint32(), hashint8(), Int64GetDatumFast, PG_GETARG_TIMETZADT_P, and PG_RETURN_UINT32.

◆ timetz_hash_extended()

Datum timetz_hash_extended ( PG_FUNCTION_ARGS  )

Definition at line 2670 of file date.c.

2671{
2673 Datum seed = PG_GETARG_DATUM(1);
2674 uint64 thash;
2675
2676 /* Same approach as timetz_hash */
2678 Int64GetDatumFast(key->time),
2679 seed));
2681 DatumGetInt64(seed)));
2683}
uint64_t uint64
Definition c.h:625
#define PG_RETURN_UINT64(x)
Definition fmgr.h:371
static uint64 DatumGetUInt64(Datum X)
Definition postgres.h:436
static int64 DatumGetInt64(Datum X)
Definition postgres.h:416

References DatumGetInt64(), DatumGetUInt64(), DirectFunctionCall2, fb(), hash_uint32_extended(), hashint8extended(), Int64GetDatumFast, PG_GETARG_DATUM, PG_GETARG_TIMETZADT_P, and PG_RETURN_UINT64.

◆ timetz_in()

Datum timetz_in ( PG_FUNCTION_ARGS  )

Definition at line 2392 of file date.c.

2393{
2394 char *str = PG_GETARG_CSTRING(0);
2395#ifdef NOT_USED
2396 Oid typelem = PG_GETARG_OID(1);
2397#endif
2398 int32 typmod = PG_GETARG_INT32(2);
2399 Node *escontext = fcinfo->context;
2401 fsec_t fsec;
2402 struct pg_tm tt,
2403 *tm = &tt;
2404 int tz;
2405 int nf;
2406 int dterr;
2407 char workbuf[MAXDATELEN + 1];
2408 char *field[MAXDATEFIELDS];
2409 int dtype;
2410 int ftype[MAXDATEFIELDS];
2411 DateTimeErrorExtra extra;
2412
2414 field, ftype, MAXDATEFIELDS, &nf);
2415 if (dterr == 0)
2416 dterr = DecodeTimeOnly(field, ftype, nf,
2417 &dtype, tm, &fsec, &tz, &extra);
2418 if (dterr != 0)
2419 {
2420 DateTimeParseError(dterr, &extra, str, "time with time zone",
2421 escontext);
2423 }
2424
2426 tm2timetz(tm, fsec, tz, result);
2427 AdjustTimeForTypmod(&(result->time), typmod);
2428
2430}

References AdjustTimeForTypmod(), DateTimeParseError(), DecodeTimeOnly(), fb(), MAXDATEFIELDS, MAXDATELEN, palloc_object, ParseDateTime(), PG_GETARG_CSTRING, PG_GETARG_INT32, PG_GETARG_OID, PG_RETURN_NULL, PG_RETURN_TIMETZADT_P, result, str, tm, and tm2timetz().

◆ timetz_izone()

Datum timetz_izone ( PG_FUNCTION_ARGS  )

Definition at line 3251 of file date.c.

3252{
3256 int tz;
3257
3259 ereport(ERROR,
3261 errmsg("interval time zone \"%s\" must be finite",
3263 PointerGetDatum(zone))))));
3264
3265 if (zone->month != 0 || zone->day != 0)
3266 ereport(ERROR,
3268 errmsg("interval time zone \"%s\" must not include months or days",
3270 PointerGetDatum(zone))))));
3271
3272 tz = -(zone->time / USECS_PER_SEC);
3273
3275
3276 result->time = time->time + (time->zone - tz) * USECS_PER_SEC;
3277 /* C99 modulo has the wrong sign convention for negative input */
3278 while (result->time < INT64CONST(0))
3279 result->time += USECS_PER_DAY;
3280 if (result->time >= USECS_PER_DAY)
3281 result->time %= USECS_PER_DAY;
3282
3283 result->zone = tz;
3284
3286}
Datum interval_out(PG_FUNCTION_ARGS)
Definition timestamp.c:974
static char * DatumGetCString(Datum X)
Definition postgres.h:365

References DatumGetCString(), DirectFunctionCall1, ereport, errcode(), errmsg, ERROR, fb(), INT64CONST, INTERVAL_NOT_FINITE, interval_out(), palloc_object, PG_GETARG_INTERVAL_P, PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, PointerGetDatum, result, TimeTzADT::time, USECS_PER_DAY, USECS_PER_SEC, and TimeTzADT::zone.

◆ timetz_larger()

Datum timetz_larger ( PG_FUNCTION_ARGS  )

Definition at line 2686 of file date.c.

2687{
2691
2693 result = time1;
2694 else
2695 result = time2;
2697}

References fb(), PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, result, and timetz_cmp_internal().

◆ timetz_le()

Datum timetz_le ( PG_FUNCTION_ARGS  )

◆ timetz_lt()

Datum timetz_lt ( PG_FUNCTION_ARGS  )

◆ timetz_mi_interval()

Datum timetz_mi_interval ( PG_FUNCTION_ARGS  )

Definition at line 2746 of file date.c.

2747{
2751
2753 ereport(ERROR,
2755 errmsg("cannot subtract infinite interval from time")));
2756
2758
2759 result->time = time->time - span->time;
2760 result->time -= result->time / USECS_PER_DAY * USECS_PER_DAY;
2761 if (result->time < INT64CONST(0))
2762 result->time += USECS_PER_DAY;
2763
2764 result->zone = time->zone;
2765
2767}

References ereport, errcode(), errmsg, ERROR, fb(), INT64CONST, INTERVAL_NOT_FINITE, palloc_object, PG_GETARG_INTERVAL_P, PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, result, TimeTzADT::time, USECS_PER_DAY, and TimeTzADT::zone.

◆ timetz_ne()

Datum timetz_ne ( PG_FUNCTION_ARGS  )

◆ timetz_out()

Datum timetz_out ( PG_FUNCTION_ARGS  )

Definition at line 2433 of file date.c.

2434{
2436 char *result;
2437 struct pg_tm tt,
2438 *tm = &tt;
2439 fsec_t fsec;
2440 int tz;
2441 char buf[MAXDATELEN + 1];
2442
2443 timetz2tm(time, tm, &fsec, &tz);
2444 EncodeTimeOnly(tm, fsec, true, tz, DateStyle, buf);
2445
2446 result = pstrdup(buf);
2448}
int timetz2tm(TimeTzADT *time, struct pg_tm *tm, fsec_t *fsec, int *tzp)
Definition date.c:2523

References buf, DateStyle, EncodeTimeOnly(), fb(), MAXDATELEN, PG_GETARG_TIMETZADT_P, PG_RETURN_CSTRING, pstrdup(), result, timetz2tm(), and tm.

Referenced by ExecGetJsonValueItemString().

◆ timetz_part()

Datum timetz_part ( PG_FUNCTION_ARGS  )

Definition at line 3171 of file date.c.

3172{
3173 return timetz_part_common(fcinfo, false);
3174}

References timetz_part_common().

◆ timetz_part_common()

static Datum timetz_part_common ( PG_FUNCTION_ARGS  ,
bool  retnumeric 
)
static

Definition at line 3054 of file date.c.

3055{
3059 int type,
3060 val;
3061 char *lowunits;
3062
3065 false);
3066
3067 type = DecodeUnits(0, lowunits, &val);
3068 if (type == UNKNOWN_FIELD)
3070
3071 if (type == UNITS)
3072 {
3073 int tz;
3074 fsec_t fsec;
3075 struct pg_tm tt,
3076 *tm = &tt;
3077
3078 timetz2tm(time, tm, &fsec, &tz);
3079
3080 switch (val)
3081 {
3082 case DTK_TZ:
3083 intresult = -tz;
3084 break;
3085
3086 case DTK_TZ_MINUTE:
3088 break;
3089
3090 case DTK_TZ_HOUR:
3091 intresult = -tz / SECS_PER_HOUR;
3092 break;
3093
3094 case DTK_MICROSEC:
3095 intresult = tm->tm_sec * INT64CONST(1000000) + fsec;
3096 break;
3097
3098 case DTK_MILLISEC:
3099 if (retnumeric)
3100 /*---
3101 * tm->tm_sec * 1000 + fsec / 1000
3102 * = (tm->tm_sec * 1'000'000 + fsec) / 1000
3103 */
3105 else
3106 PG_RETURN_FLOAT8(tm->tm_sec * 1000.0 + fsec / 1000.0);
3107 break;
3108
3109 case DTK_SECOND:
3110 if (retnumeric)
3111 /*---
3112 * tm->tm_sec + fsec / 1'000'000
3113 * = (tm->tm_sec * 1'000'000 + fsec) / 1'000'000
3114 */
3116 else
3117 PG_RETURN_FLOAT8(tm->tm_sec + fsec / 1000000.0);
3118 break;
3119
3120 case DTK_MINUTE:
3121 intresult = tm->tm_min;
3122 break;
3123
3124 case DTK_HOUR:
3125 intresult = tm->tm_hour;
3126 break;
3127
3128 case DTK_DAY:
3129 case DTK_MONTH:
3130 case DTK_QUARTER:
3131 case DTK_YEAR:
3132 case DTK_DECADE:
3133 case DTK_CENTURY:
3134 case DTK_MILLENNIUM:
3135 default:
3136 ereport(ERROR,
3138 errmsg("unit \"%s\" not supported for type %s",
3140 intresult = 0;
3141 }
3142 }
3143 else if (type == RESERV && val == DTK_EPOCH)
3144 {
3145 if (retnumeric)
3146 /*---
3147 * time->time / 1'000'000 + time->zone
3148 * = (time->time + time->zone * 1'000'000) / 1'000'000
3149 */
3150 PG_RETURN_NUMERIC(int64_div_fast_to_numeric(time->time + time->zone * INT64CONST(1000000), 6));
3151 else
3152 PG_RETURN_FLOAT8(time->time / 1000000.0 + time->zone);
3153 }
3154 else
3155 {
3156 ereport(ERROR,
3158 errmsg("unit \"%s\" not recognized for type %s",
3160 intresult = 0;
3161 }
3162
3163 if (retnumeric)
3165 else
3167}
#define SECS_PER_HOUR
Definition timestamp.h:127

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, fb(), format_type_be(), int64_div_fast_to_numeric(), int64_to_numeric(), INT64CONST, MINS_PER_HOUR, PG_GETARG_TEXT_PP, PG_GETARG_TIMETZADT_P, PG_RETURN_FLOAT8, PG_RETURN_NUMERIC, RESERV, SECS_PER_HOUR, SECS_PER_MINUTE, TimeTzADT::time, timetz2tm(), tm, pg_tm::tm_hour, pg_tm::tm_min, pg_tm::tm_sec, type, UNITS, UNKNOWN_FIELD, val, VARDATA_ANY(), VARSIZE_ANY_EXHDR(), and TimeTzADT::zone.

Referenced by extract_timetz(), and timetz_part().

◆ timetz_pl_interval()

Datum timetz_pl_interval ( PG_FUNCTION_ARGS  )

Definition at line 2718 of file date.c.

2719{
2723
2725 ereport(ERROR,
2727 errmsg("cannot add infinite interval to time")));
2728
2730
2731 result->time = time->time + span->time;
2732 result->time -= result->time / USECS_PER_DAY * USECS_PER_DAY;
2733 if (result->time < INT64CONST(0))
2734 result->time += USECS_PER_DAY;
2735
2736 result->zone = time->zone;
2737
2739}

References ereport, errcode(), errmsg, ERROR, fb(), INT64CONST, INTERVAL_NOT_FINITE, palloc_object, PG_GETARG_INTERVAL_P, PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, result, TimeTzADT::time, USECS_PER_DAY, and TimeTzADT::zone.

◆ timetz_recv()

Datum timetz_recv ( PG_FUNCTION_ARGS  )

Definition at line 2454 of file date.c.

2455{
2457
2458#ifdef NOT_USED
2459 Oid typelem = PG_GETARG_OID(1);
2460#endif
2461 int32 typmod = PG_GETARG_INT32(2);
2463
2465
2466 result->time = pq_getmsgint64(buf);
2467
2468 if (result->time < INT64CONST(0) || result->time > USECS_PER_DAY)
2469 ereport(ERROR,
2471 errmsg("time out of range")));
2472
2473 result->zone = pq_getmsgint(buf, sizeof(result->zone));
2474
2475 /* Check for sane GMT displacement; see notes in datatype/timestamp.h */
2476 if (result->zone <= -TZDISP_LIMIT || result->zone >= TZDISP_LIMIT)
2477 ereport(ERROR,
2479 errmsg("time zone displacement out of range")));
2480
2481 AdjustTimeForTypmod(&(result->time), typmod);
2482
2484}
#define TZDISP_LIMIT
Definition timestamp.h:144

References AdjustTimeForTypmod(), buf, ereport, errcode(), errmsg, ERROR, fb(), INT64CONST, palloc_object, PG_GETARG_INT32, PG_GETARG_OID, PG_GETARG_POINTER, PG_RETURN_TIMETZADT_P, pq_getmsgint(), pq_getmsgint64(), result, TZDISP_LIMIT, and USECS_PER_DAY.

◆ timetz_scale()

Datum timetz_scale ( PG_FUNCTION_ARGS  )

Definition at line 2546 of file date.c.

2547{
2549 int32 typmod = PG_GETARG_INT32(1);
2551
2553
2554 result->time = time->time;
2555 result->zone = time->zone;
2556
2557 AdjustTimeForTypmod(&(result->time), typmod);
2558
2560}

References AdjustTimeForTypmod(), palloc_object, PG_GETARG_INT32, PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, result, TimeTzADT::time, and TimeTzADT::zone.

◆ timetz_send()

◆ timetz_smaller()

Datum timetz_smaller ( PG_FUNCTION_ARGS  )

Definition at line 2700 of file date.c.

2701{
2705
2707 result = time1;
2708 else
2709 result = time2;
2711}

References fb(), PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, result, and timetz_cmp_internal().

◆ timetz_time()

Datum timetz_time ( PG_FUNCTION_ARGS  )

Definition at line 2939 of file date.c.

2940{
2943
2944 /* swallow the time zone and just return the time */
2945 result = timetz->time;
2946
2948}

References fb(), PG_GETARG_TIMETZADT_P, PG_RETURN_TIMEADT, and result.

Referenced by executeDateTimeMethod().

◆ timetz_zone()

Datum timetz_zone ( PG_FUNCTION_ARGS  )

Definition at line 3188 of file date.c.

3189{
3193 int tz;
3194 char tzname[TZ_STRLEN_MAX + 1];
3195 int type,
3196 val;
3197 pg_tz *tzp;
3198
3199 /*
3200 * Look up the requested timezone.
3201 */
3203
3204 type = DecodeTimezoneName(tzname, &val, &tzp);
3205
3207 {
3208 /* fixed-offset abbreviation */
3209 tz = -val;
3210 }
3211 else if (type == TZNAME_DYNTZ)
3212 {
3213 /* dynamic-offset abbreviation, resolve using transaction start time */
3215 int isdst;
3216
3218 }
3219 else
3220 {
3221 /* Get the offset-from-GMT that is valid now for the zone name */
3223 struct pg_tm tm;
3224 fsec_t fsec;
3225
3226 if (timestamp2tm(now, &tz, &tm, &fsec, NULL, tzp) != 0)
3227 ereport(ERROR,
3229 errmsg("timestamp out of range")));
3230 }
3231
3233
3234 result->time = t->time + (t->zone - tz) * USECS_PER_SEC;
3235 /* C99 modulo has the wrong sign convention for negative input */
3236 while (result->time < INT64CONST(0))
3237 result->time += USECS_PER_DAY;
3238 if (result->time >= USECS_PER_DAY)
3239 result->time %= USECS_PER_DAY;
3240
3241 result->zone = tz;
3242
3244}
int DetermineTimeZoneAbbrevOffsetTS(TimestampTz ts, const char *abbr, pg_tz *tzp, int *isdst)
Definition datetime.c:1810
int DecodeTimezoneName(const char *tzname, int *offset, pg_tz **tz)
Definition datetime.c:3309
Datum now(PG_FUNCTION_ARGS)
Definition timestamp.c:1613
#define TZNAME_FIXED_OFFSET
Definition datetime.h:301
#define TZNAME_DYNTZ
Definition datetime.h:302
#define TZ_STRLEN_MAX
Definition pgtime.h:54
Definition pgtz.h:66
void text_to_cstring_buffer(const text *src, char *dst, size_t dst_len)
Definition varlena.c:248
TimestampTz GetCurrentTransactionStartTimestamp(void)
Definition xact.c:872

References DecodeTimezoneName(), DetermineTimeZoneAbbrevOffsetTS(), ereport, errcode(), errmsg, ERROR, fb(), GetCurrentTransactionStartTimestamp(), INT64CONST, now(), palloc_object, PG_GETARG_TEXT_PP, PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, result, text_to_cstring_buffer(), TimeTzADT::time, timestamp2tm(), tm, type, TZ_STRLEN_MAX, TZNAME_DYNTZ, TZNAME_FIXED_OFFSET, USECS_PER_DAY, USECS_PER_SEC, val, and TimeTzADT::zone.

Referenced by timetz_at_local().

◆ timetztypmodin()

Datum timetztypmodin ( PG_FUNCTION_ARGS  )

Definition at line 2502 of file date.c.

2503{
2505
2507}

References anytime_typmodin(), fb(), PG_GETARG_ARRAYTYPE_P, and PG_RETURN_INT32.

◆ timetztypmodout()

Datum timetztypmodout ( PG_FUNCTION_ARGS  )

Definition at line 2510 of file date.c.

2511{
2512 int32 typmod = PG_GETARG_INT32(0);
2513
2514 PG_RETURN_CSTRING(anytime_typmodout(true, typmod));
2515}

References anytime_typmodout(), PG_GETARG_INT32, and PG_RETURN_CSTRING.

◆ tm2time()

int tm2time ( struct pg_tm tm,
fsec_t  fsec,
TimeADT result 
)

Definition at line 1518 of file date.c.

1519{
1521 * USECS_PER_SEC) + fsec;
1522 return 0;
1523}

References MINS_PER_HOUR, result, SECS_PER_MINUTE, tm, pg_tm::tm_hour, pg_tm::tm_min, pg_tm::tm_sec, and USECS_PER_SEC.

Referenced by GetSQLLocalTime(), parse_datetime(), and time_in().

◆ tm2timetz()

int tm2timetz ( struct pg_tm tm,
fsec_t  fsec,
int  tz,
TimeTzADT result 
)

Definition at line 2382 of file date.c.

2383{
2384 result->time = ((((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *
2385 USECS_PER_SEC) + fsec;
2386 result->zone = tz;
2387
2388 return 0;
2389}

References MINS_PER_HOUR, result, SECS_PER_MINUTE, tm, pg_tm::tm_hour, pg_tm::tm_min, pg_tm::tm_sec, and USECS_PER_SEC.

Referenced by GetSQLCurrentTime(), parse_datetime(), timestamptz_timetz(), and timetz_in().