]> granicus.if.org Git - postgresql/commitdiff
Attempting to insert a value of 'now' into a datetime type
authorBruce Momjian <bruce@momjian.us>
Sun, 14 Mar 1999 16:44:02 +0000 (16:44 +0000)
committerBruce Momjian <bruce@momjian.us>
Sun, 14 Mar 1999 16:44:02 +0000 (16:44 +0000)
results in a bogus datetime value under AlphaLinux.  (Note that
the link to submit a port-specific bug on your website is broken)

-Test Case:
----------
testdb=> create table dttest (dt datetime);
testdb=> insert into dttest values ('now');

--------------------------------------------------------------------------

Solution:
---------
The basic problem is the typedefs of AbsoluteTime and RelativeTime,
which are both 'int32'.  These types appear to be used synonymously
with the 'time_t' type, which on AlphaLinux is typedef'd as a 'long
int', which is 64-bits (not 32).  The solution included here fixes
the datetime type (it now passes the regression test), but does not
pass the absolute and relative time regression tests.  Presumably, a
more thorough investigation of how these types are used is warranted.
The included patch is from the v6.3.2 source, but can be applied to
the v6.4.2 source.  Please note that there is also a RedHat-specific
patch distributed with the PostgreSQL source package from RedHat
that was applied first.

Rich Edwards

src/backend/utils/adt/date.c
src/include/utils/builtins.h
src/include/utils/nabstime.h

index afad0ecbf7a15018ca38fa43ba1085181fda3556..e582ebc2c655f7bb38f1d634212ad5b1009b7e95 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.30 1999/02/21 03:49:27 scrappy Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.31 1999/03/14 16:44:01 momjian Exp $
  *
  * NOTES
  *      This code is actually (almost) unused.
@@ -94,7 +94,7 @@ static int    sec_tab[] = {
  * Function prototypes -- internal to this file only
  */
 
-static void reltime2tm(int32 time, struct tm * tm);
+static void reltime2tm(RelativeTime time, struct tm * tm);
 
 #ifdef NOT_USED
 static int     correct_unit(char *unit, int *unptr);
@@ -161,7 +161,7 @@ reltimein(char *str)
  *             reltimeout              - converts the internal format to a reltime string
  */
 char *
-reltimeout(int32 time)
+reltimeout(RelativeTime time)
 {
        char       *result;
        struct tm       tt,
@@ -193,7 +193,7 @@ do { \
 } while(0)
 
 static void
-reltime2tm(int32 time, struct tm * tm)
+reltime2tm(RelativeTime time, struct tm * tm)
 {
        TMODULO(time, tm->tm_year, 31536000);
        TMODULO(time, tm->tm_mon, 2592000);
index f947dff613a02ca84fa5cb2b08e95ad116f05301..9522169dcdcd53c57dbeba02e272f837232dd45b 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: builtins.h,v 1.75 1999/03/14 05:09:05 momjian Exp $
+ * $Id: builtins.h,v 1.76 1999/03/14 16:44:01 momjian Exp $
  *
  * NOTES
  *       This should normally only be included by fmgr.h.
@@ -195,8 +195,8 @@ extern int32 pqtest(struct varlena * vlena);
 /* arrayfuncs.c */
 
 /* date.c */
-extern int32 reltimein(char *timestring);
-extern char *reltimeout(int32 timevalue);
+extern RelativeTime reltimein(char *timestring);
+extern char *reltimeout(RelativeTime timevalue);
 extern TimeInterval tintervalin(char *intervalstr);
 extern char *tintervalout(TimeInterval interval);
 extern RelativeTime timespan_reltime(TimeSpan *timespan);
index 58a262d3aab34d5bf43e7d45eedfb76ea584226c..fca6b628770bd56afa1a755d1db0e55ad60f2506 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: nabstime.h,v 1.18 1999/02/13 23:22:25 momjian Exp $
+ * $Id: nabstime.h,v 1.19 1999/03/14 16:44:02 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
  *
  * ----------------------------------------------------------------
  */
-typedef int32 AbsoluteTime;
-typedef int32 RelativeTime;
+/* The original typedefs are bogus - they assume that the system's 'time_t'
+ * type is of size 32-bits.  Under AlphaLinux, time_t is a long int, which
+ * is 64-bits.  Therefore, typedef these both as simply 'time_t', and let
+ * the OS define what the size really is. -- RME 3/5/99
+ */
+typedef time_t AbsoluteTime;
+typedef time_t RelativeTime;
 
 typedef struct
 {