Skip to content

Commit e025bb7

Browse files
author
Thomas G. Lockhart
committed
Define macros for handling typmod manipulation for date/time types.
Should be more robust than all of that brute-force inline code. Rename macros for masking and typmod manipulation to put TIMESTAMP_ or INTERVAL_ in front of the macro name, to reduce the possibility of name space collisions.
1 parent 043f9eb commit e025bb7

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/include/utils/timestamp.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: timestamp.h,v 1.27 2002/06/20 20:29:53 momjian Exp $
9+
* $Id: timestamp.h,v 1.28 2002/08/04 06:42:18 thomas Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -52,6 +52,10 @@ typedef struct
5252
} Interval;
5353

5454

55+
#define MAX_TIMESTAMP_PRECISION 6
56+
#define MAX_INTERVAL_PRECISION 6
57+
58+
5559
/*
5660
* Macros for fmgr-callable functions.
5761
*
@@ -117,10 +121,6 @@ typedef struct
117121

118122
#define TIMESTAMP_NOT_FINITE(j) (TIMESTAMP_IS_NOBEGIN(j) || TIMESTAMP_IS_NOEND(j))
119123

120-
121-
#define MAX_TIMESTAMP_PRECISION 6
122-
#define MAX_INTERVAL_PRECISION 6
123-
124124
#ifdef HAVE_INT64_TIMESTAMP
125125

126126
typedef int32 fsec_t;
@@ -134,6 +134,18 @@ typedef double fsec_t;
134134

135135
#endif
136136

137+
#define TIMESTAMP_MASK(b) (1 << (b))
138+
#define INTERVAL_MASK(b) (1 << (b))
139+
140+
/* Macros to handle packing and unpacking the typmod field for intervals */
141+
#define INTERVAL_FULL_RANGE (0x7FFF)
142+
#define INTERVAL_RANGE_MASK (0x7FFF)
143+
#define INTERVAL_FULL_PRECISION (0xFFFF)
144+
#define INTERVAL_PRECISION_MASK (0xFFFF)
145+
#define INTERVAL_TYPMOD(p,r) ((((r) & INTERVAL_RANGE_MASK) << 16) | ((p) & INTERVAL_PRECISION_MASK))
146+
#define INTERVAL_PRECISION(t) ((t) & INTERVAL_PRECISION_MASK)
147+
#define INTERVAL_RANGE(t) (((t) >> 16) & INTERVAL_RANGE_MASK)
148+
137149

138150
/*
139151
* timestamp.c prototypes

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy