mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-03-01 19:45:33 +08:00
Features added:
* Wrote max(date) and min(date) aggregates * Wrote operator "-" for date; date - date yields number of days difference * Wrote operator+(date,int) and operator-(date,int); the int is the number of days. Each operator returns a new date. By: Tom Tromey <tromey@creche.cygnus.com>
This commit is contained in:
parent
eedc75bfe1
commit
8abc490181
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/datetimes.c,v 1.6 1996/11/10 03:03:10 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/datetimes.c,v 1.7 1996/11/14 21:38:58 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -224,6 +224,104 @@ date_cmp(int4 dateVal1, int4 dateVal2)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int4
|
||||
date_larger(int4 dateVal1, int4 dateVal2)
|
||||
{
|
||||
return (date_gt (dateVal1, dateVal2) ? dateVal1 : dateVal2);
|
||||
}
|
||||
|
||||
int4
|
||||
date_smaller(int4 dateVal1, int4 dateVal2)
|
||||
{
|
||||
return (date_lt (dateVal1, dateVal2) ? dateVal1 : dateVal2);
|
||||
}
|
||||
|
||||
/* Compute difference between two dates in days. */
|
||||
int32
|
||||
date_mi(int4 dateVal1, int4 dateVal2)
|
||||
{
|
||||
DateADT *date1, *date2;
|
||||
int32 days = 0;
|
||||
int i;
|
||||
|
||||
date1 = (DateADT *) &dateVal1;
|
||||
date2 = (DateADT *) &dateVal2;
|
||||
|
||||
/* Sum number of days in each full year between date1 and date2. */
|
||||
for (i = date1->year + 1; i < date2->year; ++i)
|
||||
days += isleap (i) ? 366 : 365;
|
||||
|
||||
/* Add in number of days in each full month from date1 to end of
|
||||
year. */
|
||||
for (i = date1->month + 1; i <= 12; ++i)
|
||||
days += day_tab[isleap (date1->year)][i - 1];
|
||||
|
||||
/* Add in number of days in each full month from start of year to
|
||||
date2. */
|
||||
for (i = 1; i < date2->month; ++i)
|
||||
days += day_tab[isleap (date2->year)][i - 1];
|
||||
|
||||
/* Add in number of days left in month for date1. */
|
||||
days += day_tab[isleap (date1->year)][date1->month - 1] - date1->day;
|
||||
|
||||
/* Add in day of month of date2. */
|
||||
days += date2->day;
|
||||
|
||||
return (days);
|
||||
}
|
||||
|
||||
/* Add a number of days to a date, giving a new date.
|
||||
Must handle both positive and negative numbers of days. */
|
||||
int4
|
||||
date_pli(int4 dateVal, int32 days)
|
||||
{
|
||||
DateADT *date1 = (DateADT *) &dateVal;
|
||||
/* Use separate day variable because date1->day is a narrow type. */
|
||||
int32 day = date1->day + days;
|
||||
|
||||
if (days > 0)
|
||||
{
|
||||
/* Loop as long as day has wrapped around end of month. */
|
||||
while (day > day_tab[isleap (date1->year)][date1->month - 1])
|
||||
{
|
||||
day -= day_tab[isleap (date1->year)][date1->month - 1];
|
||||
if (++date1->month > 12)
|
||||
{
|
||||
/* Month wrapped around. */
|
||||
date1->month = 1;
|
||||
++date1->year;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Loop as long as day has wrapped around beginning of month. */
|
||||
while (day < 1)
|
||||
{
|
||||
/* Decrement month first, because a negative day number
|
||||
should be held as relative to the previous month's end. */
|
||||
if (--date1->month < 1)
|
||||
{
|
||||
/* Month wrapped around. */
|
||||
date1->month = 12;
|
||||
--date1->year;
|
||||
}
|
||||
|
||||
day += day_tab[isleap (date1->year)][date1->month - 1];
|
||||
}
|
||||
}
|
||||
date1->day = day;
|
||||
|
||||
return (dateVal);
|
||||
}
|
||||
|
||||
/* Subtract a number of days from a date, giving a new date. */
|
||||
int4
|
||||
date_mii(int4 dateVal, int32 days)
|
||||
{
|
||||
return (date_pli (dateVal, -days));
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* Time ADT
|
||||
*****************************************************************************/
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: pg_aggregate.h,v 1.2 1996/10/31 09:47:04 scrappy Exp $
|
||||
* $Id: pg_aggregate.h,v 1.3 1996/11/14 21:39:07 scrappy Exp $
|
||||
*
|
||||
* NOTES
|
||||
* the genbki.sh script reads this file and generates .bki
|
||||
@ -101,11 +101,13 @@ DATA(insert OID = 0 ( max PGUID int4larger - - 23 23 0 23 _null_ _null_
|
||||
DATA(insert OID = 0 ( max PGUID int2larger - - 21 21 0 21 _null_ _null_ ));
|
||||
DATA(insert OID = 0 ( max PGUID float4larger - - 700 700 0 700 _null_ _null_ ));
|
||||
DATA(insert OID = 0 ( max PGUID float8larger - - 701 701 0 701 _null_ _null_ ));
|
||||
DATA(insert OID = 0 ( max PGUID date_larger - - 1082 1082 0 1082 _null_ _null_ ));
|
||||
|
||||
DATA(insert OID = 0 ( min PGUID int4smaller - - 23 23 0 23 _null_ _null_ ));
|
||||
DATA(insert OID = 0 ( min PGUID int2smaller - - 21 21 0 21 _null_ _null_ ));
|
||||
DATA(insert OID = 0 ( min PGUID float4smaller - - 700 700 0 700 _null_ _null_ ));
|
||||
DATA(insert OID = 0 ( min PGUID float8smaller - - 701 701 0 701 _null_ _null_ ));
|
||||
DATA(insert OID = 0 ( min PGUID date_smaller - - 1082 1082 0 1082 _null_ _null_ ));
|
||||
|
||||
DATA(insert OID = 0 ( count PGUID - int4inc - 0 0 23 23 _null_ 0 ));
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: pg_operator.h,v 1.3 1996/11/13 20:50:58 scrappy Exp $
|
||||
* $Id: pg_operator.h,v 1.4 1996/11/14 21:39:11 scrappy Exp $
|
||||
*
|
||||
* NOTES
|
||||
* the genbki.sh script reads this file and generates .bki
|
||||
@ -389,6 +389,9 @@ DATA(insert OID = 1095 ( "<" PGUID 0 b t f 1082 1082 16 1097 1098 0 0
|
||||
DATA(insert OID = 1096 ( "<=" PGUID 0 b t f 1082 1082 16 1098 1097 0 0 date_le intltsel intltjoinsel ));
|
||||
DATA(insert OID = 1097 ( ">" PGUID 0 b t f 1082 1082 16 1095 1096 0 0 date_gt intltsel intltjoinsel ));
|
||||
DATA(insert OID = 1098 ( ">=" PGUID 0 b t f 1082 1082 16 1096 1065 0 0 date_ge intltsel intltjoinsel ));
|
||||
DATA(insert OID = 1099 ( "-" PGUID 0 b t f 1082 1082 23 0 0 0 0 date_mi - - ));
|
||||
DATA(insert OID = 1100 ( "+" PGUID 0 b t f 1082 23 1082 0 0 0 0 date_pli - - ));
|
||||
DATA(insert OID = 1101 ( "-" PGUID 0 b t f 1082 23 1082 0 0 0 0 date_mii - - ));
|
||||
|
||||
DATA(insert OID = 1108 ( "=" PGUID 0 b t t 1083 1083 16 1108 1109 1110 1110 time_eq eqsel eqjoinsel ));
|
||||
DATA(insert OID = 1109 ( "<>" PGUID 0 b t f 1083 1083 16 1109 1108 0 0 time_ne neqsel neqjoinsel ));
|
||||
|
@ -6,7 +6,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: pg_proc.h,v 1.6 1996/11/13 20:51:01 scrappy Exp $
|
||||
* $Id: pg_proc.h,v 1.7 1996/11/14 21:39:14 scrappy Exp $
|
||||
*
|
||||
* NOTES
|
||||
* The script catalog/genbki.sh reads this file and generates .bki
|
||||
@ -727,7 +727,11 @@ DATA(insert OID = 1089 ( date_gt PGUID 11 f t f 2 f 16 "1082 1082" 100
|
||||
DATA(insert OID = 1090 ( date_ge PGUID 11 f t f 2 f 16 "1082 1082" 100 0 0 100 foo bar ));
|
||||
DATA(insert OID = 1091 ( date_ne PGUID 11 f t f 2 f 16 "1082 1082" 100 0 0 100 foo bar ));
|
||||
DATA(insert OID = 1092 ( date_cmp PGUID 11 f t f 2 f 23 "1082 1082" 100 0 0 100 foo bar ));
|
||||
|
||||
DATA(insert OID = 1093 ( date_larger PGUID 11 f t f 2 f 1082 "1082 1082" 100 0 0 100 foo bar ));
|
||||
DATA(insert OID = 1094 ( date_smaller PGUID 11 f t f 2 f 1082 "1082 1082" 100 0 0 100 foo bar ));
|
||||
DATA(insert OID = 1095 ( date_mi PGUID 11 f t f 2 f 23 "1082 1082" 100 0 0 100 foo bar ));
|
||||
DATA(insert OID = 1096 ( date_pli PGUID 11 f t f 2 f 1082 "1082 23" 100 0 0 100 foo bar ));
|
||||
DATA(insert OID = 1097 ( date_mii PGUID 11 f t f 2 f 1082 "1082 23" 100 0 0 100 foo bar ));
|
||||
DATA(insert OID = 1099 ( time_in PGUID 11 f t f 1 f 1083 "0" 100 0 0 100 foo bar ));
|
||||
|
||||
/* OIDS 1100 - 1199 */
|
||||
|
Loading…
Reference in New Issue
Block a user