mirror of
https://github.com/postgres/postgres.git
synced 2025-05-13 01:13:08 -04:00
Move Timestamp/Interval typedefs and basic macros into datatype/timestamp.h.
As per my recent proposal, this refactors things so that these typedefs and macros are available in a header that can be included in frontend-ish code. I also changed various headers that were undesirably including utils/timestamp.h to include datatype/timestamp.h instead. Unsurprisingly, this showed that half the system was getting utils/timestamp.h by way of xlog.h. No actual code changes here, just header refactoring.
This commit is contained in:
parent
d63de337f3
commit
a7801b62f2
@ -7,6 +7,7 @@
|
|||||||
#include "btree_utils_num.h"
|
#include "btree_utils_num.h"
|
||||||
#include "utils/cash.h"
|
#include "utils/cash.h"
|
||||||
#include "utils/date.h"
|
#include "utils/date.h"
|
||||||
|
#include "utils/timestamp.h"
|
||||||
|
|
||||||
|
|
||||||
GISTENTRY *
|
GISTENTRY *
|
||||||
|
@ -19,6 +19,7 @@ OH, me, I'm Terry Mackintosh <terry@terrym.com>
|
|||||||
#include "executor/spi.h"
|
#include "executor/spi.h"
|
||||||
#include "commands/trigger.h"
|
#include "commands/trigger.h"
|
||||||
#include "utils/rel.h"
|
#include "utils/rel.h"
|
||||||
|
#include "utils/timestamp.h"
|
||||||
|
|
||||||
PG_MODULE_MAGIC;
|
PG_MODULE_MAGIC;
|
||||||
|
|
||||||
|
@ -1904,7 +1904,7 @@ memcpy(destination->data, buffer, 40);
|
|||||||
<row>
|
<row>
|
||||||
<entry><type>interval</type></entry>
|
<entry><type>interval</type></entry>
|
||||||
<entry><type>Interval*</type></entry>
|
<entry><type>Interval*</type></entry>
|
||||||
<entry><filename>utils/timestamp.h</filename></entry>
|
<entry><filename>datatype/timestamp.h</filename></entry>
|
||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<entry><type>lseg</type></entry>
|
<entry><type>lseg</type></entry>
|
||||||
@ -1969,7 +1969,7 @@ memcpy(destination->data, buffer, 40);
|
|||||||
<row>
|
<row>
|
||||||
<entry><type>timestamp</type></entry>
|
<entry><type>timestamp</type></entry>
|
||||||
<entry><type>Timestamp*</type></entry>
|
<entry><type>Timestamp*</type></entry>
|
||||||
<entry><filename>utils/timestamp.h</filename></entry>
|
<entry><filename>datatype/timestamp.h</filename></entry>
|
||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<entry><type>tinterval</type></entry>
|
<entry><type>tinterval</type></entry>
|
||||||
|
@ -64,6 +64,7 @@
|
|||||||
#include "storage/smgr.h"
|
#include "storage/smgr.h"
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
#include "utils/memutils.h"
|
#include "utils/memutils.h"
|
||||||
|
#include "utils/timestamp.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -49,6 +49,7 @@
|
|||||||
#include "utils/memutils.h"
|
#include "utils/memutils.h"
|
||||||
#include "utils/relmapper.h"
|
#include "utils/relmapper.h"
|
||||||
#include "utils/snapmgr.h"
|
#include "utils/snapmgr.h"
|
||||||
|
#include "utils/timestamp.h"
|
||||||
#include "pg_trace.h"
|
#include "pg_trace.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@
|
|||||||
#include "utils/guc.h"
|
#include "utils/guc.h"
|
||||||
#include "utils/ps_status.h"
|
#include "utils/ps_status.h"
|
||||||
#include "utils/relmapper.h"
|
#include "utils/relmapper.h"
|
||||||
|
#include "utils/timestamp.h"
|
||||||
#include "pg_trace.h"
|
#include "pg_trace.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,6 +48,7 @@
|
|||||||
#include "utils/pg_rusage.h"
|
#include "utils/pg_rusage.h"
|
||||||
#include "utils/syscache.h"
|
#include "utils/syscache.h"
|
||||||
#include "utils/tuplesort.h"
|
#include "utils/tuplesort.h"
|
||||||
|
#include "utils/timestamp.h"
|
||||||
#include "utils/tqual.h"
|
#include "utils/tqual.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -132,6 +132,7 @@
|
|||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
#include "utils/memutils.h"
|
#include "utils/memutils.h"
|
||||||
#include "utils/ps_status.h"
|
#include "utils/ps_status.h"
|
||||||
|
#include "utils/timestamp.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include "tcop/utility.h"
|
#include "tcop/utility.h"
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
#include "utils/snapmgr.h"
|
#include "utils/snapmgr.h"
|
||||||
|
#include "utils/timestamp.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
#include "utils/fmgroids.h"
|
#include "utils/fmgroids.h"
|
||||||
#include "utils/syscache.h"
|
#include "utils/syscache.h"
|
||||||
|
#include "utils/timestamp.h"
|
||||||
#include "utils/tqual.h"
|
#include "utils/tqual.h"
|
||||||
|
|
||||||
/* Potentially set by contrib/pg_upgrade_support functions */
|
/* Potentially set by contrib/pg_upgrade_support functions */
|
||||||
|
@ -53,6 +53,7 @@
|
|||||||
#include "utils/lsyscache.h"
|
#include "utils/lsyscache.h"
|
||||||
#include "utils/memutils.h"
|
#include "utils/memutils.h"
|
||||||
#include "utils/pg_rusage.h"
|
#include "utils/pg_rusage.h"
|
||||||
|
#include "utils/timestamp.h"
|
||||||
#include "utils/tqual.h"
|
#include "utils/tqual.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
#include "utils/syscache.h"
|
#include "utils/syscache.h"
|
||||||
#include "utils/snapmgr.h"
|
#include "utils/snapmgr.h"
|
||||||
|
#include "utils/timestamp.h"
|
||||||
#include "mb/pg_wchar.h"
|
#include "mb/pg_wchar.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include "miscadmin.h"
|
#include "miscadmin.h"
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
#include "utils/syscache.h"
|
#include "utils/syscache.h"
|
||||||
|
#include "utils/timestamp.h"
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "parser/parse_expr.h"
|
#include "parser/parse_expr.h"
|
||||||
#include "parser/parse_relation.h"
|
#include "parser/parse_relation.h"
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
|
#include "utils/int8.h"
|
||||||
#include "utils/lsyscache.h"
|
#include "utils/lsyscache.h"
|
||||||
#include "utils/syscache.h"
|
#include "utils/syscache.h"
|
||||||
#include "utils/varbit.h"
|
#include "utils/varbit.h"
|
||||||
|
@ -97,6 +97,7 @@
|
|||||||
#include "utils/rel.h"
|
#include "utils/rel.h"
|
||||||
#include "utils/snapmgr.h"
|
#include "utils/snapmgr.h"
|
||||||
#include "utils/syscache.h"
|
#include "utils/syscache.h"
|
||||||
|
#include "utils/timestamp.h"
|
||||||
#include "utils/tqual.h"
|
#include "utils/tqual.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,6 +62,7 @@
|
|||||||
#include "utils/memutils.h"
|
#include "utils/memutils.h"
|
||||||
#include "utils/ps_status.h"
|
#include "utils/ps_status.h"
|
||||||
#include "utils/rel.h"
|
#include "utils/rel.h"
|
||||||
|
#include "utils/timestamp.h"
|
||||||
#include "utils/tqual.h"
|
#include "utils/tqual.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@
|
|||||||
#include "utils/guc.h"
|
#include "utils/guc.h"
|
||||||
#include "utils/ps_status.h"
|
#include "utils/ps_status.h"
|
||||||
#include "utils/resowner.h"
|
#include "utils/resowner.h"
|
||||||
|
#include "utils/timestamp.h"
|
||||||
|
|
||||||
/* Global variable to indicate if this process is a walreceiver process */
|
/* Global variable to indicate if this process is a walreceiver process */
|
||||||
bool am_walreceiver;
|
bool am_walreceiver;
|
||||||
|
@ -62,6 +62,7 @@
|
|||||||
#include "utils/memutils.h"
|
#include "utils/memutils.h"
|
||||||
#include "utils/ps_status.h"
|
#include "utils/ps_status.h"
|
||||||
#include "utils/resowner.h"
|
#include "utils/resowner.h"
|
||||||
|
#include "utils/timestamp.h"
|
||||||
|
|
||||||
|
|
||||||
/* Array of WalSnds in shared memory */
|
/* Array of WalSnds in shared memory */
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
#include "storage/standby.h"
|
#include "storage/standby.h"
|
||||||
#include "utils/rel.h"
|
#include "utils/rel.h"
|
||||||
#include "utils/resowner.h"
|
#include "utils/resowner.h"
|
||||||
|
#include "utils/timestamp.h"
|
||||||
|
|
||||||
|
|
||||||
/* Note: these two macros only work on shared buffers, not local ones! */
|
/* Note: these two macros only work on shared buffers, not local ones! */
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "storage/sinvaladt.h"
|
#include "storage/sinvaladt.h"
|
||||||
#include "storage/standby.h"
|
#include "storage/standby.h"
|
||||||
#include "utils/ps_status.h"
|
#include "utils/ps_status.h"
|
||||||
|
#include "utils/timestamp.h"
|
||||||
|
|
||||||
/* User-settable GUC parameters */
|
/* User-settable GUC parameters */
|
||||||
int vacuum_defer_cleanup_age;
|
int vacuum_defer_cleanup_age;
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
#include "storage/procarray.h"
|
#include "storage/procarray.h"
|
||||||
#include "storage/procsignal.h"
|
#include "storage/procsignal.h"
|
||||||
#include "storage/spin.h"
|
#include "storage/spin.h"
|
||||||
|
#include "utils/timestamp.h"
|
||||||
|
|
||||||
|
|
||||||
/* GUC variables */
|
/* GUC variables */
|
||||||
|
@ -72,6 +72,7 @@
|
|||||||
#include "utils/memutils.h"
|
#include "utils/memutils.h"
|
||||||
#include "utils/ps_status.h"
|
#include "utils/ps_status.h"
|
||||||
#include "utils/snapmgr.h"
|
#include "utils/snapmgr.h"
|
||||||
|
#include "utils/timestamp.h"
|
||||||
#include "mb/pg_wchar.h"
|
#include "mb/pg_wchar.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "utils/array.h"
|
#include "utils/array.h"
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
#include "utils/date.h"
|
#include "utils/date.h"
|
||||||
|
#include "utils/datetime.h"
|
||||||
#include "utils/nabstime.h"
|
#include "utils/nabstime.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "storage/fd.h"
|
#include "storage/fd.h"
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
#include "utils/memutils.h"
|
#include "utils/memutils.h"
|
||||||
|
#include "utils/timestamp.h"
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "catalog/catalog.h"
|
#include "catalog/catalog.h"
|
||||||
#include "catalog/pg_type.h"
|
|
||||||
#include "catalog/pg_tablespace.h"
|
#include "catalog/pg_tablespace.h"
|
||||||
|
#include "catalog/pg_type.h"
|
||||||
#include "commands/dbcommands.h"
|
#include "commands/dbcommands.h"
|
||||||
#include "funcapi.h"
|
#include "funcapi.h"
|
||||||
#include "miscadmin.h"
|
#include "miscadmin.h"
|
||||||
@ -30,8 +30,9 @@
|
|||||||
#include "storage/fd.h"
|
#include "storage/fd.h"
|
||||||
#include "storage/pmsignal.h"
|
#include "storage/pmsignal.h"
|
||||||
#include "storage/procarray.h"
|
#include "storage/procarray.h"
|
||||||
#include "utils/builtins.h"
|
|
||||||
#include "tcop/tcopprot.h"
|
#include "tcop/tcopprot.h"
|
||||||
|
#include "utils/builtins.h"
|
||||||
|
#include "utils/timestamp.h"
|
||||||
|
|
||||||
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
|
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "libpq/pqformat.h"
|
#include "libpq/pqformat.h"
|
||||||
#include "miscadmin.h"
|
#include "miscadmin.h"
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
|
#include "utils/datetime.h"
|
||||||
#include "utils/nabstime.h"
|
#include "utils/nabstime.h"
|
||||||
|
|
||||||
#define MIN_DAYNUM (-24856) /* December 13, 1901 */
|
#define MIN_DAYNUM (-24856) /* December 13, 1901 */
|
||||||
|
@ -14,13 +14,14 @@
|
|||||||
*/
|
*/
|
||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
|
|
||||||
|
#include "catalog/pg_type.h"
|
||||||
#include "funcapi.h"
|
#include "funcapi.h"
|
||||||
|
#include "libpq/ip.h"
|
||||||
#include "miscadmin.h"
|
#include "miscadmin.h"
|
||||||
#include "pgstat.h"
|
#include "pgstat.h"
|
||||||
#include "catalog/pg_type.h"
|
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
#include "utils/inet.h"
|
#include "utils/inet.h"
|
||||||
#include "libpq/ip.h"
|
#include "utils/timestamp.h"
|
||||||
|
|
||||||
/* bogus ... these externs should be in a header file */
|
/* bogus ... these externs should be in a header file */
|
||||||
extern Datum pg_stat_get_numscans(PG_FUNCTION_ARGS);
|
extern Datum pg_stat_get_numscans(PG_FUNCTION_ARGS);
|
||||||
|
@ -124,6 +124,7 @@
|
|||||||
#include "utils/selfuncs.h"
|
#include "utils/selfuncs.h"
|
||||||
#include "utils/spccache.h"
|
#include "utils/spccache.h"
|
||||||
#include "utils/syscache.h"
|
#include "utils/syscache.h"
|
||||||
|
#include "utils/timestamp.h"
|
||||||
#include "utils/tqual.h"
|
#include "utils/tqual.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "miscadmin.h"
|
#include "miscadmin.h"
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
#include "utils/memutils.h"
|
#include "utils/memutils.h"
|
||||||
|
#include "utils/timestamp.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Estimate of the maximum number of open portals a user would have,
|
* Estimate of the maximum number of open portals a user would have,
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include "access/gist.h"
|
#include "access/gist.h"
|
||||||
#include "access/itup.h"
|
#include "access/itup.h"
|
||||||
|
#include "fmgr.h"
|
||||||
#include "storage/bufmgr.h"
|
#include "storage/bufmgr.h"
|
||||||
#include "storage/buffile.h"
|
#include "storage/buffile.h"
|
||||||
#include "utils/rbtree.h"
|
#include "utils/rbtree.h"
|
||||||
|
@ -13,10 +13,10 @@
|
|||||||
|
|
||||||
#include "access/rmgr.h"
|
#include "access/rmgr.h"
|
||||||
#include "access/xlogdefs.h"
|
#include "access/xlogdefs.h"
|
||||||
|
#include "datatype/timestamp.h"
|
||||||
#include "lib/stringinfo.h"
|
#include "lib/stringinfo.h"
|
||||||
#include "storage/buf.h"
|
#include "storage/buf.h"
|
||||||
#include "utils/pg_crc.h"
|
#include "utils/pg_crc.h"
|
||||||
#include "utils/timestamp.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The overall layout of an XLOG record is:
|
* The overall layout of an XLOG record is:
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
#define XLOG_INTERNAL_H
|
#define XLOG_INTERNAL_H
|
||||||
|
|
||||||
#include "access/xlog.h"
|
#include "access/xlog.h"
|
||||||
|
#include "fmgr.h"
|
||||||
|
#include "pgtime.h"
|
||||||
#include "storage/block.h"
|
#include "storage/block.h"
|
||||||
#include "storage/relfilenode.h"
|
#include "storage/relfilenode.h"
|
||||||
|
|
||||||
|
@ -13,9 +13,10 @@
|
|||||||
#ifndef SEQUENCE_H
|
#ifndef SEQUENCE_H
|
||||||
#define SEQUENCE_H
|
#define SEQUENCE_H
|
||||||
|
|
||||||
|
#include "access/xlog.h"
|
||||||
|
#include "fmgr.h"
|
||||||
#include "nodes/parsenodes.h"
|
#include "nodes/parsenodes.h"
|
||||||
#include "storage/relfilenode.h"
|
#include "storage/relfilenode.h"
|
||||||
#include "access/xlog.h"
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct FormData_pg_sequence
|
typedef struct FormData_pg_sequence
|
||||||
|
163
src/include/datatype/timestamp.h
Normal file
163
src/include/datatype/timestamp.h
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* timestamp.h
|
||||||
|
* Timestamp and Interval typedefs and related macros.
|
||||||
|
*
|
||||||
|
* Note: this file must be includable in both frontend and backend contexts.
|
||||||
|
*
|
||||||
|
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
|
||||||
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
|
*
|
||||||
|
* src/include/datatype/timestamp.h
|
||||||
|
*
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
#ifndef DATATYPE_TIMESTAMP_H
|
||||||
|
#define DATATYPE_TIMESTAMP_H
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <float.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Timestamp represents absolute time.
|
||||||
|
*
|
||||||
|
* Interval represents delta time. Keep track of months (and years), days,
|
||||||
|
* and hours/minutes/seconds separately since the elapsed time spanned is
|
||||||
|
* unknown until instantiated relative to an absolute time.
|
||||||
|
*
|
||||||
|
* Note that Postgres uses "time interval" to mean a bounded interval,
|
||||||
|
* consisting of a beginning and ending time, not a time span - thomas 97/03/20
|
||||||
|
*
|
||||||
|
* We have two implementations, one that uses int64 values with units of
|
||||||
|
* microseconds, and one that uses double values with units of seconds.
|
||||||
|
*
|
||||||
|
* TimeOffset and fsec_t are convenience typedefs for temporary variables
|
||||||
|
* that are of different types in the two cases. Do not use fsec_t in values
|
||||||
|
* stored on-disk, since it is not the same size in both implementations.
|
||||||
|
* Also, fsec_t is only meant for *fractional* seconds; beware of overflow
|
||||||
|
* if the value you need to store could be many seconds.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
|
|
||||||
|
typedef int64 Timestamp;
|
||||||
|
typedef int64 TimestampTz;
|
||||||
|
typedef int64 TimeOffset;
|
||||||
|
typedef int32 fsec_t; /* fractional seconds (in microseconds) */
|
||||||
|
#else
|
||||||
|
|
||||||
|
typedef double Timestamp;
|
||||||
|
typedef double TimestampTz;
|
||||||
|
typedef double TimeOffset;
|
||||||
|
typedef double fsec_t; /* fractional seconds (in seconds) */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
TimeOffset time; /* all time units other than days, months and
|
||||||
|
* years */
|
||||||
|
int32 day; /* days, after time for alignment */
|
||||||
|
int32 month; /* months and years, after time for alignment */
|
||||||
|
} Interval;
|
||||||
|
|
||||||
|
|
||||||
|
#define MAX_TIMESTAMP_PRECISION 6
|
||||||
|
#define MAX_INTERVAL_PRECISION 6
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Round off to MAX_TIMESTAMP_PRECISION decimal places.
|
||||||
|
* Note: this is also used for rounding off intervals.
|
||||||
|
*/
|
||||||
|
#define TS_PREC_INV 1000000.0
|
||||||
|
#define TSROUND(j) (rint(((double) (j)) * TS_PREC_INV) / TS_PREC_INV)
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Assorted constants for datetime-related calculations
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define DAYS_PER_YEAR 365.25 /* assumes leap year every four years */
|
||||||
|
#define MONTHS_PER_YEAR 12
|
||||||
|
/*
|
||||||
|
* DAYS_PER_MONTH is very imprecise. The more accurate value is
|
||||||
|
* 365.2425/12 = 30.436875, or '30 days 10:29:06'. Right now we only
|
||||||
|
* return an integral number of days, but someday perhaps we should
|
||||||
|
* also return a 'time' value to be used as well. ISO 8601 suggests
|
||||||
|
* 30 days.
|
||||||
|
*/
|
||||||
|
#define DAYS_PER_MONTH 30 /* assumes exactly 30 days per month */
|
||||||
|
#define HOURS_PER_DAY 24 /* assume no daylight savings time changes */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This doesn't adjust for uneven daylight savings time intervals or leap
|
||||||
|
* seconds, and it crudely estimates leap years. A more accurate value
|
||||||
|
* for days per years is 365.2422.
|
||||||
|
*/
|
||||||
|
#define SECS_PER_YEAR (36525 * 864) /* avoid floating-point computation */
|
||||||
|
#define SECS_PER_DAY 86400
|
||||||
|
#define SECS_PER_HOUR 3600
|
||||||
|
#define SECS_PER_MINUTE 60
|
||||||
|
#define MINS_PER_HOUR 60
|
||||||
|
|
||||||
|
#define USECS_PER_DAY INT64CONST(86400000000)
|
||||||
|
#define USECS_PER_HOUR INT64CONST(3600000000)
|
||||||
|
#define USECS_PER_MINUTE INT64CONST(60000000)
|
||||||
|
#define USECS_PER_SEC INT64CONST(1000000)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* DT_NOBEGIN represents timestamp -infinity; DT_NOEND represents +infinity
|
||||||
|
*/
|
||||||
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
|
#define DT_NOBEGIN (-INT64CONST(0x7fffffffffffffff) - 1)
|
||||||
|
#define DT_NOEND (INT64CONST(0x7fffffffffffffff))
|
||||||
|
#else /* !HAVE_INT64_TIMESTAMP */
|
||||||
|
#ifdef HUGE_VAL
|
||||||
|
#define DT_NOBEGIN (-HUGE_VAL)
|
||||||
|
#define DT_NOEND (HUGE_VAL)
|
||||||
|
#else
|
||||||
|
#define DT_NOBEGIN (-DBL_MAX)
|
||||||
|
#define DT_NOEND (DBL_MAX)
|
||||||
|
#endif
|
||||||
|
#endif /* HAVE_INT64_TIMESTAMP */
|
||||||
|
|
||||||
|
#define TIMESTAMP_NOBEGIN(j) \
|
||||||
|
do {(j) = DT_NOBEGIN;} while (0)
|
||||||
|
|
||||||
|
#define TIMESTAMP_IS_NOBEGIN(j) ((j) == DT_NOBEGIN)
|
||||||
|
|
||||||
|
#define TIMESTAMP_NOEND(j) \
|
||||||
|
do {(j) = DT_NOEND;} while (0)
|
||||||
|
|
||||||
|
#define TIMESTAMP_IS_NOEND(j) ((j) == DT_NOEND)
|
||||||
|
|
||||||
|
#define TIMESTAMP_NOT_FINITE(j) (TIMESTAMP_IS_NOBEGIN(j) || TIMESTAMP_IS_NOEND(j))
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Julian date support.
|
||||||
|
*
|
||||||
|
* IS_VALID_JULIAN checks the minimum date exactly, but is a bit sloppy
|
||||||
|
* about the maximum, since it's far enough out to not be especially
|
||||||
|
* interesting.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define JULIAN_MINYEAR (-4713)
|
||||||
|
#define JULIAN_MINMONTH (11)
|
||||||
|
#define JULIAN_MINDAY (24)
|
||||||
|
#define JULIAN_MAXYEAR (5874898)
|
||||||
|
|
||||||
|
#define IS_VALID_JULIAN(y,m,d) \
|
||||||
|
(((y) > JULIAN_MINYEAR \
|
||||||
|
|| ((y) == JULIAN_MINYEAR && \
|
||||||
|
((m) > JULIAN_MINMONTH \
|
||||||
|
|| ((m) == JULIAN_MINMONTH && (d) >= JULIAN_MINDAY)))) \
|
||||||
|
&& (y) < JULIAN_MAXYEAR)
|
||||||
|
|
||||||
|
#define JULIAN_MAX (2147483494) /* == date2j(JULIAN_MAXYEAR, 1, 1) */
|
||||||
|
|
||||||
|
/* Julian-date equivalents of Day 0 in Unix and Postgres reckoning */
|
||||||
|
#define UNIX_EPOCH_JDATE 2440588 /* == date2j(1970, 1, 1) */
|
||||||
|
#define POSTGRES_EPOCH_JDATE 2451545 /* == date2j(2000, 1, 1) */
|
||||||
|
|
||||||
|
#endif /* DATATYPE_TIMESTAMP_H */
|
@ -65,9 +65,9 @@ typedef struct
|
|||||||
#endif
|
#endif
|
||||||
#endif /* ENABLE_SSPI */
|
#endif /* ENABLE_SSPI */
|
||||||
|
|
||||||
|
#include "datatype/timestamp.h"
|
||||||
#include "libpq/hba.h"
|
#include "libpq/hba.h"
|
||||||
#include "libpq/pqcomm.h"
|
#include "libpq/pqcomm.h"
|
||||||
#include "utils/timestamp.h"
|
|
||||||
|
|
||||||
|
|
||||||
typedef enum CAC_state
|
typedef enum CAC_state
|
||||||
|
@ -11,11 +11,12 @@
|
|||||||
#ifndef PGSTAT_H
|
#ifndef PGSTAT_H
|
||||||
#define PGSTAT_H
|
#define PGSTAT_H
|
||||||
|
|
||||||
|
#include "datatype/timestamp.h"
|
||||||
|
#include "fmgr.h"
|
||||||
#include "libpq/pqcomm.h"
|
#include "libpq/pqcomm.h"
|
||||||
#include "portability/instr_time.h"
|
#include "portability/instr_time.h"
|
||||||
#include "utils/hsearch.h"
|
#include "utils/hsearch.h"
|
||||||
#include "utils/relcache.h"
|
#include "utils/relcache.h"
|
||||||
#include "utils/timestamp.h"
|
|
||||||
|
|
||||||
|
|
||||||
/* Values for track_functions GUC variable --- order is significant! */
|
/* Values for track_functions GUC variable --- order is significant! */
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
#define _WALPROTOCOL_H
|
#define _WALPROTOCOL_H
|
||||||
|
|
||||||
#include "access/xlogdefs.h"
|
#include "access/xlogdefs.h"
|
||||||
#include "utils/timestamp.h"
|
#include "datatype/timestamp.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#define _WALSENDER_H
|
#define _WALSENDER_H
|
||||||
|
|
||||||
#include "access/xlog.h"
|
#include "access/xlog.h"
|
||||||
|
#include "fmgr.h"
|
||||||
#include "nodes/nodes.h"
|
#include "nodes/nodes.h"
|
||||||
#include "storage/latch.h"
|
#include "storage/latch.h"
|
||||||
#include "storage/shmem.h"
|
#include "storage/shmem.h"
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
#define _PROC_H_
|
#define _PROC_H_
|
||||||
|
|
||||||
#include "access/xlog.h"
|
#include "access/xlog.h"
|
||||||
|
#include "datatype/timestamp.h"
|
||||||
#include "storage/latch.h"
|
#include "storage/latch.h"
|
||||||
#include "storage/lock.h"
|
#include "storage/lock.h"
|
||||||
#include "storage/pg_sema.h"
|
#include "storage/pg_sema.h"
|
||||||
#include "utils/timestamp.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Each backend advertises up to PGPROC_MAX_CACHED_SUBXIDS TransactionIds
|
* Each backend advertises up to PGPROC_MAX_CACHED_SUBXIDS TransactionIds
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*-------------------------------------------------------------------------
|
/*-------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* datetime.h
|
* datetime.h
|
||||||
* Definitions for the date/time and other date/time support code.
|
* Definitions for date/time support code.
|
||||||
* The support code is shared with other date data types,
|
* The support code is shared with other date data types,
|
||||||
* including abstime, reltime, date, and time.
|
* including abstime, reltime, date, and time.
|
||||||
*
|
*
|
||||||
@ -16,9 +16,6 @@
|
|||||||
#ifndef DATETIME_H
|
#ifndef DATETIME_H
|
||||||
#define DATETIME_H
|
#define DATETIME_H
|
||||||
|
|
||||||
#include <limits.h>
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#include "utils/timestamp.h"
|
#include "utils/timestamp.h"
|
||||||
|
|
||||||
/* this struct is declared in utils/tzparser.h: */
|
/* this struct is declared in utils/tzparser.h: */
|
||||||
@ -254,30 +251,6 @@ extern const int day_tab[2][13];
|
|||||||
#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
|
#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
|
||||||
|
|
||||||
|
|
||||||
/* Julian date support for date2j() and j2date()
|
|
||||||
*
|
|
||||||
* IS_VALID_JULIAN checks the minimum date exactly, but is a bit sloppy
|
|
||||||
* about the maximum, since it's far enough out to not be especially
|
|
||||||
* interesting.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define JULIAN_MINYEAR (-4713)
|
|
||||||
#define JULIAN_MINMONTH (11)
|
|
||||||
#define JULIAN_MINDAY (24)
|
|
||||||
#define JULIAN_MAXYEAR (5874898)
|
|
||||||
|
|
||||||
#define IS_VALID_JULIAN(y,m,d) ((((y) > JULIAN_MINYEAR) \
|
|
||||||
|| (((y) == JULIAN_MINYEAR) && (((m) > JULIAN_MINMONTH) \
|
|
||||||
|| (((m) == JULIAN_MINMONTH) && ((d) >= JULIAN_MINDAY))))) \
|
|
||||||
&& ((y) < JULIAN_MAXYEAR))
|
|
||||||
|
|
||||||
#define JULIAN_MAX (2147483494) /* == date2j(JULIAN_MAXYEAR, 1 ,1) */
|
|
||||||
|
|
||||||
/* Julian-date equivalents of Day 0 in Unix and Postgres reckoning */
|
|
||||||
#define UNIX_EPOCH_JDATE 2440588 /* == date2j(1970, 1, 1) */
|
|
||||||
#define POSTGRES_EPOCH_JDATE 2451545 /* == date2j(2000, 1, 1) */
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Datetime input parsing routines (ParseDateTime, DecodeDateTime, etc)
|
* Datetime input parsing routines (ParseDateTime, DecodeDateTime, etc)
|
||||||
* return zero or a positive value on success. On failure, they return
|
* return zero or a positive value on success. On failure, they return
|
||||||
|
@ -17,8 +17,7 @@
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
#include "fmgr.h"
|
#include "fmgr.h"
|
||||||
#include "utils/timestamp.h"
|
#include "pgtime.h"
|
||||||
#include "utils/datetime.h"
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------
|
/* ----------------------------------------------------------------
|
||||||
|
@ -46,9 +46,9 @@
|
|||||||
#ifndef PORTAL_H
|
#ifndef PORTAL_H
|
||||||
#define PORTAL_H
|
#define PORTAL_H
|
||||||
|
|
||||||
|
#include "datatype/timestamp.h"
|
||||||
#include "executor/execdesc.h"
|
#include "executor/execdesc.h"
|
||||||
#include "utils/resowner.h"
|
#include "utils/resowner.h"
|
||||||
#include "utils/timestamp.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We have several execution strategies for Portals, depending on what
|
* We have several execution strategies for Portals, depending on what
|
||||||
|
@ -13,90 +13,10 @@
|
|||||||
#ifndef TIMESTAMP_H
|
#ifndef TIMESTAMP_H
|
||||||
#define TIMESTAMP_H
|
#define TIMESTAMP_H
|
||||||
|
|
||||||
#include <math.h>
|
#include "datatype/timestamp.h"
|
||||||
#include <limits.h>
|
|
||||||
#include <float.h>
|
|
||||||
|
|
||||||
#include "fmgr.h"
|
#include "fmgr.h"
|
||||||
#include "pgtime.h"
|
#include "pgtime.h"
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
|
||||||
#include "utils/int8.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Timestamp represents absolute time.
|
|
||||||
*
|
|
||||||
* Interval represents delta time. Keep track of months (and years), days,
|
|
||||||
* and hours/minutes/seconds separately since the elapsed time spanned is
|
|
||||||
* unknown until instantiated relative to an absolute time.
|
|
||||||
*
|
|
||||||
* Note that Postgres uses "time interval" to mean a bounded interval,
|
|
||||||
* consisting of a beginning and ending time, not a time span - thomas 97/03/20
|
|
||||||
*
|
|
||||||
* We have two implementations, one that uses int64 values with units of
|
|
||||||
* microseconds, and one that uses double values with units of seconds.
|
|
||||||
*
|
|
||||||
* TimeOffset and fsec_t are convenience typedefs for temporary variables
|
|
||||||
* that are of different types in the two cases. Do not use fsec_t in values
|
|
||||||
* stored on-disk, since it is not the same size in both implementations.
|
|
||||||
* Also, fsec_t is only meant for *fractional* seconds; beware of overflow
|
|
||||||
* if the value you need to store could be many seconds.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
|
||||||
|
|
||||||
typedef int64 Timestamp;
|
|
||||||
typedef int64 TimestampTz;
|
|
||||||
typedef int64 TimeOffset;
|
|
||||||
typedef int32 fsec_t; /* fractional seconds (in microseconds) */
|
|
||||||
#else
|
|
||||||
|
|
||||||
typedef double Timestamp;
|
|
||||||
typedef double TimestampTz;
|
|
||||||
typedef double TimeOffset;
|
|
||||||
typedef double fsec_t; /* fractional seconds (in seconds) */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
TimeOffset time; /* all time units other than days, months and
|
|
||||||
* years */
|
|
||||||
int32 day; /* days, after time for alignment */
|
|
||||||
int32 month; /* months and years, after time for alignment */
|
|
||||||
} Interval;
|
|
||||||
|
|
||||||
|
|
||||||
#define MAX_TIMESTAMP_PRECISION 6
|
|
||||||
#define MAX_INTERVAL_PRECISION 6
|
|
||||||
|
|
||||||
/* in both timestamp.h and ecpg/dt.h */
|
|
||||||
#define DAYS_PER_YEAR 365.25 /* assumes leap year every four years */
|
|
||||||
#define MONTHS_PER_YEAR 12
|
|
||||||
/*
|
|
||||||
* DAYS_PER_MONTH is very imprecise. The more accurate value is
|
|
||||||
* 365.2425/12 = 30.436875, or '30 days 10:29:06'. Right now we only
|
|
||||||
* return an integral number of days, but someday perhaps we should
|
|
||||||
* also return a 'time' value to be used as well. ISO 8601 suggests
|
|
||||||
* 30 days.
|
|
||||||
*/
|
|
||||||
#define DAYS_PER_MONTH 30 /* assumes exactly 30 days per month */
|
|
||||||
#define HOURS_PER_DAY 24 /* assume no daylight savings time changes */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This doesn't adjust for uneven daylight savings time intervals or leap
|
|
||||||
* seconds, and it crudely estimates leap years. A more accurate value
|
|
||||||
* for days per years is 365.2422.
|
|
||||||
*/
|
|
||||||
#define SECS_PER_YEAR (36525 * 864) /* avoid floating-point computation */
|
|
||||||
#define SECS_PER_DAY 86400
|
|
||||||
#define SECS_PER_HOUR 3600
|
|
||||||
#define SECS_PER_MINUTE 60
|
|
||||||
#define MINS_PER_HOUR 60
|
|
||||||
|
|
||||||
#define USECS_PER_DAY INT64CONST(86400000000)
|
|
||||||
#define USECS_PER_HOUR INT64CONST(3600000000)
|
|
||||||
#define USECS_PER_MINUTE INT64CONST(60000000)
|
|
||||||
#define USECS_PER_SEC INT64CONST(1000000)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Macros for fmgr-callable functions.
|
* Macros for fmgr-callable functions.
|
||||||
@ -123,8 +43,6 @@ typedef struct
|
|||||||
#define PG_RETURN_TIMESTAMPTZ(x) return TimestampTzGetDatum(x)
|
#define PG_RETURN_TIMESTAMPTZ(x) return TimestampTzGetDatum(x)
|
||||||
#define PG_RETURN_INTERVAL_P(x) return IntervalPGetDatum(x)
|
#define PG_RETURN_INTERVAL_P(x) return IntervalPGetDatum(x)
|
||||||
|
|
||||||
#define DT_NOBEGIN (-INT64CONST(0x7fffffffffffffff) - 1)
|
|
||||||
#define DT_NOEND (INT64CONST(0x7fffffffffffffff))
|
|
||||||
#else /* !HAVE_INT64_TIMESTAMP */
|
#else /* !HAVE_INT64_TIMESTAMP */
|
||||||
|
|
||||||
#define DatumGetTimestamp(X) ((Timestamp) DatumGetFloat8(X))
|
#define DatumGetTimestamp(X) ((Timestamp) DatumGetFloat8(X))
|
||||||
@ -143,33 +61,9 @@ typedef struct
|
|||||||
#define PG_RETURN_TIMESTAMPTZ(x) return TimestampTzGetDatum(x)
|
#define PG_RETURN_TIMESTAMPTZ(x) return TimestampTzGetDatum(x)
|
||||||
#define PG_RETURN_INTERVAL_P(x) return IntervalPGetDatum(x)
|
#define PG_RETURN_INTERVAL_P(x) return IntervalPGetDatum(x)
|
||||||
|
|
||||||
#ifdef HUGE_VAL
|
|
||||||
#define DT_NOBEGIN (-HUGE_VAL)
|
|
||||||
#define DT_NOEND (HUGE_VAL)
|
|
||||||
#else
|
|
||||||
#define DT_NOBEGIN (-DBL_MAX)
|
|
||||||
#define DT_NOEND (DBL_MAX)
|
|
||||||
#endif
|
|
||||||
#endif /* HAVE_INT64_TIMESTAMP */
|
#endif /* HAVE_INT64_TIMESTAMP */
|
||||||
|
|
||||||
|
|
||||||
#define TIMESTAMP_NOBEGIN(j) \
|
|
||||||
do {(j) = DT_NOBEGIN;} while (0)
|
|
||||||
#define TIMESTAMP_IS_NOBEGIN(j) ((j) == DT_NOBEGIN)
|
|
||||||
|
|
||||||
#define TIMESTAMP_NOEND(j) \
|
|
||||||
do {(j) = DT_NOEND;} while (0)
|
|
||||||
#define TIMESTAMP_IS_NOEND(j) ((j) == DT_NOEND)
|
|
||||||
|
|
||||||
#define TIMESTAMP_NOT_FINITE(j) (TIMESTAMP_IS_NOBEGIN(j) || TIMESTAMP_IS_NOEND(j))
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Round off to MAX_TIMESTAMP_PRECISION decimal places.
|
|
||||||
* Note: this is also used for rounding off intervals.
|
|
||||||
*/
|
|
||||||
#define TS_PREC_INV 1000000.0
|
|
||||||
#define TSROUND(j) (rint(((double) (j)) * TS_PREC_INV) / TS_PREC_INV)
|
|
||||||
|
|
||||||
#define TIMESTAMP_MASK(b) (1 << (b))
|
#define TIMESTAMP_MASK(b) (1 << (b))
|
||||||
#define INTERVAL_MASK(b) (1 << (b))
|
#define INTERVAL_MASK(b) (1 << (b))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user