Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* date.h
|
|
|
|
* Definitions for the SQL92 "date" and "time" types.
|
|
|
|
*
|
|
|
|
*
|
2004-12-31 23:04:05 +01:00
|
|
|
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
2005-10-15 04:49:52 +02:00
|
|
|
* $PostgreSQL: pgsql/src/include/utils/date.h,v 1.32 2005/10/15 02:49:46 momjian Exp $
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef DATE_H
|
|
|
|
#define DATE_H
|
|
|
|
|
2000-06-09 03:11:16 +02:00
|
|
|
#include "fmgr.h"
|
|
|
|
|
|
|
|
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
typedef int32 DateADT;
|
|
|
|
|
2002-04-21 21:52:18 +02:00
|
|
|
#ifdef HAVE_INT64_TIMESTAMP
|
|
|
|
typedef int64 TimeADT;
|
|
|
|
#else
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
typedef float8 TimeADT;
|
2002-04-21 21:52:18 +02:00
|
|
|
#endif
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
|
2000-03-15 00:06:59 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
2002-04-21 21:52:18 +02:00
|
|
|
#ifdef HAVE_INT64_TIMESTAMP
|
2005-10-15 04:49:52 +02:00
|
|
|
int64 time; /* all time units other than months and years */
|
2002-04-21 21:52:18 +02:00
|
|
|
#else
|
2005-10-15 04:49:52 +02:00
|
|
|
double time; /* all time units other than months and years */
|
2002-04-21 21:52:18 +02:00
|
|
|
#endif
|
2002-09-04 22:31:48 +02:00
|
|
|
int32 zone; /* numeric time zone, in seconds */
|
2000-03-15 00:06:59 +01:00
|
|
|
} TimeTzADT;
|
|
|
|
|
2005-02-25 17:13:29 +01:00
|
|
|
/*
|
|
|
|
* Macros for fmgr-callable functions.
|
|
|
|
*
|
|
|
|
* For TimeADT, we make use of the same support routines as for float8 or int64.
|
|
|
|
* Therefore TimeADT is pass-by-reference if and only if float8 or int64 is!
|
|
|
|
*/
|
2002-04-21 21:52:18 +02:00
|
|
|
#ifdef HAVE_INT64_TIMESTAMP
|
2005-02-25 17:13:29 +01:00
|
|
|
|
2002-04-21 21:52:18 +02:00
|
|
|
#define MAX_TIME_PRECISION 6
|
2005-02-25 17:13:29 +01:00
|
|
|
|
|
|
|
#define DatumGetDateADT(X) ((DateADT) DatumGetInt32(X))
|
|
|
|
#define DatumGetTimeADT(X) ((TimeADT) DatumGetInt64(X))
|
|
|
|
#define DatumGetTimeTzADTP(X) ((TimeTzADT *) DatumGetPointer(X))
|
|
|
|
|
|
|
|
#define DateADTGetDatum(X) Int32GetDatum(X)
|
|
|
|
#define TimeADTGetDatum(X) Int64GetDatum(X)
|
|
|
|
#define TimeTzADTPGetDatum(X) PointerGetDatum(X)
|
2002-04-21 21:52:18 +02:00
|
|
|
#else
|
2005-02-25 17:13:29 +01:00
|
|
|
|
2003-01-29 02:08:42 +01:00
|
|
|
#define MAX_TIME_PRECISION 10
|
2002-04-21 21:52:18 +02:00
|
|
|
|
2005-10-09 19:21:47 +02:00
|
|
|
/* round off to MAX_TIME_PRECISION decimal places */
|
|
|
|
#define TIME_PREC_INV 10000000000.0
|
|
|
|
#define TIMEROUND(j) (rint(((double) (j)) * TIME_PREC_INV) / TIME_PREC_INV)
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
#define DatumGetDateADT(X) ((DateADT) DatumGetInt32(X))
|
|
|
|
#define DatumGetTimeADT(X) ((TimeADT) DatumGetFloat8(X))
|
2000-06-09 03:11:16 +02:00
|
|
|
#define DatumGetTimeTzADTP(X) ((TimeTzADT *) DatumGetPointer(X))
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
#define DateADTGetDatum(X) Int32GetDatum(X)
|
|
|
|
#define TimeADTGetDatum(X) Float8GetDatum(X)
|
2000-06-09 03:11:16 +02:00
|
|
|
#define TimeTzADTPGetDatum(X) PointerGetDatum(X)
|
2005-10-15 04:49:52 +02:00
|
|
|
#endif /* HAVE_INT64_TIMESTAMP */
|
2005-02-25 17:13:29 +01:00
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
#define PG_GETARG_DATEADT(n) DatumGetDateADT(PG_GETARG_DATUM(n))
|
|
|
|
#define PG_GETARG_TIMEADT(n) DatumGetTimeADT(PG_GETARG_DATUM(n))
|
2000-06-09 03:11:16 +02:00
|
|
|
#define PG_GETARG_TIMETZADT_P(n) DatumGetTimeTzADTP(PG_GETARG_DATUM(n))
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
#define PG_RETURN_DATEADT(x) return DateADTGetDatum(x)
|
|
|
|
#define PG_RETURN_TIMEADT(x) return TimeADTGetDatum(x)
|
2000-06-09 03:11:16 +02:00
|
|
|
#define PG_RETURN_TIMETZADT_P(x) return TimeTzADTPGetDatum(x)
|
|
|
|
|
|
|
|
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
/* date.c */
|
2000-06-09 03:11:16 +02:00
|
|
|
extern Datum date_in(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_out(PG_FUNCTION_ARGS);
|
2003-05-13 01:08:52 +02:00
|
|
|
extern Datum date_recv(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_send(PG_FUNCTION_ARGS);
|
2000-06-09 03:11:16 +02:00
|
|
|
extern Datum date_eq(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_ne(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_lt(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_le(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_gt(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_ge(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_cmp(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_larger(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_smaller(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_mi(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_pli(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_mii(PG_FUNCTION_ARGS);
|
2004-02-14 21:16:18 +01:00
|
|
|
extern Datum date_eq_timestamp(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_ne_timestamp(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_lt_timestamp(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_le_timestamp(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_gt_timestamp(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_ge_timestamp(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_cmp_timestamp(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_eq_timestamptz(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_ne_timestamptz(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_lt_timestamptz(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_le_timestamptz(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_gt_timestamptz(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_ge_timestamptz(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_cmp_timestamptz(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timestamp_eq_date(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timestamp_ne_date(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timestamp_lt_date(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timestamp_le_date(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timestamp_gt_date(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timestamp_ge_date(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timestamp_cmp_date(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timestamptz_eq_date(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timestamptz_ne_date(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timestamptz_lt_date(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timestamptz_le_date(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timestamptz_gt_date(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timestamptz_ge_date(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timestamptz_cmp_date(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_pl_interval(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_mi_interval(PG_FUNCTION_ARGS);
|
2000-06-09 03:11:16 +02:00
|
|
|
extern Datum date_timestamp(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timestamp_date(PG_FUNCTION_ARGS);
|
2001-09-28 10:09:14 +02:00
|
|
|
extern Datum date_timestamptz(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timestamptz_date(PG_FUNCTION_ARGS);
|
2000-06-09 03:11:16 +02:00
|
|
|
extern Datum datetime_timestamp(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum abstime_date(PG_FUNCTION_ARGS);
|
2000-11-11 20:55:39 +01:00
|
|
|
extern Datum text_date(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum date_text(PG_FUNCTION_ARGS);
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
|
2000-06-09 03:11:16 +02:00
|
|
|
extern Datum time_in(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum time_out(PG_FUNCTION_ARGS);
|
2003-05-13 01:08:52 +02:00
|
|
|
extern Datum time_recv(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum time_send(PG_FUNCTION_ARGS);
|
2001-10-03 07:29:27 +02:00
|
|
|
extern Datum time_scale(PG_FUNCTION_ARGS);
|
2000-06-09 03:11:16 +02:00
|
|
|
extern Datum time_eq(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum time_ne(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum time_lt(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum time_le(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum time_gt(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum time_ge(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum time_cmp(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum overlaps_time(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum time_larger(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum time_smaller(PG_FUNCTION_ARGS);
|
2001-09-28 10:09:14 +02:00
|
|
|
extern Datum time_mi_time(PG_FUNCTION_ARGS);
|
2000-06-09 03:11:16 +02:00
|
|
|
extern Datum timestamp_time(PG_FUNCTION_ARGS);
|
2002-04-21 21:52:18 +02:00
|
|
|
extern Datum timestamptz_time(PG_FUNCTION_ARGS);
|
2000-06-09 03:11:16 +02:00
|
|
|
extern Datum time_interval(PG_FUNCTION_ARGS);
|
2000-12-03 15:51:12 +01:00
|
|
|
extern Datum interval_time(PG_FUNCTION_ARGS);
|
2000-11-11 20:55:39 +01:00
|
|
|
extern Datum text_time(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum time_text(PG_FUNCTION_ARGS);
|
2000-12-03 15:51:12 +01:00
|
|
|
extern Datum time_pl_interval(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum time_mi_interval(PG_FUNCTION_ARGS);
|
2002-04-21 21:52:18 +02:00
|
|
|
extern Datum time_part(PG_FUNCTION_ARGS);
|
2000-03-15 00:06:59 +01:00
|
|
|
|
2000-06-09 03:11:16 +02:00
|
|
|
extern Datum timetz_in(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timetz_out(PG_FUNCTION_ARGS);
|
2003-05-13 01:08:52 +02:00
|
|
|
extern Datum timetz_recv(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timetz_send(PG_FUNCTION_ARGS);
|
2001-10-03 07:29:27 +02:00
|
|
|
extern Datum timetz_scale(PG_FUNCTION_ARGS);
|
2000-06-09 03:11:16 +02:00
|
|
|
extern Datum timetz_eq(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timetz_ne(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timetz_lt(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timetz_le(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timetz_gt(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timetz_ge(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timetz_cmp(PG_FUNCTION_ARGS);
|
2000-06-19 05:55:01 +02:00
|
|
|
extern Datum timetz_hash(PG_FUNCTION_ARGS);
|
2000-06-09 03:11:16 +02:00
|
|
|
extern Datum overlaps_timetz(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timetz_larger(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timetz_smaller(PG_FUNCTION_ARGS);
|
2001-09-28 10:09:14 +02:00
|
|
|
extern Datum timetz_time(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum time_timetz(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timestamptz_timetz(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum datetimetz_timestamptz(PG_FUNCTION_ARGS);
|
2000-11-11 20:55:39 +01:00
|
|
|
extern Datum text_timetz(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timetz_text(PG_FUNCTION_ARGS);
|
2001-10-18 19:30:21 +02:00
|
|
|
extern Datum timetz_part(PG_FUNCTION_ARGS);
|
2001-09-28 10:09:14 +02:00
|
|
|
extern Datum timetz_zone(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timetz_izone(PG_FUNCTION_ARGS);
|
2000-12-03 15:51:12 +01:00
|
|
|
extern Datum timetz_pl_interval(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timetz_mi_interval(PG_FUNCTION_ARGS);
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* DATE_H */
|