Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8abc490

Browse files
committed
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>
1 parenteedc75b commit8abc490

File tree

4 files changed

+112
-5
lines changed

4 files changed

+112
-5
lines changed

‎src/backend/utils/adt/datetimes.c

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/datetimes.c,v 1.6 1996/11/10 03:03:10 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/datetimes.c,v 1.7 1996/11/14 21:38:58 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -224,6 +224,104 @@ date_cmp(int4 dateVal1, int4 dateVal2)
224224
return0;
225225
}
226226

227+
int4
228+
date_larger(int4dateVal1,int4dateVal2)
229+
{
230+
return (date_gt (dateVal1,dateVal2) ?dateVal1 :dateVal2);
231+
}
232+
233+
int4
234+
date_smaller(int4dateVal1,int4dateVal2)
235+
{
236+
return (date_lt (dateVal1,dateVal2) ?dateVal1 :dateVal2);
237+
}
238+
239+
/* Compute difference between two dates in days. */
240+
int32
241+
date_mi(int4dateVal1,int4dateVal2)
242+
{
243+
DateADT*date1,*date2;
244+
int32days=0;
245+
inti;
246+
247+
date1= (DateADT*)&dateVal1;
248+
date2= (DateADT*)&dateVal2;
249+
250+
/* Sum number of days in each full year between date1 and date2. */
251+
for (i=date1->year+1;i<date2->year;++i)
252+
days+=isleap (i) ?366 :365;
253+
254+
/* Add in number of days in each full month from date1 to end of
255+
year. */
256+
for (i=date1->month+1;i <=12;++i)
257+
days+=day_tab[isleap (date1->year)][i-1];
258+
259+
/* Add in number of days in each full month from start of year to
260+
date2. */
261+
for (i=1;i<date2->month;++i)
262+
days+=day_tab[isleap (date2->year)][i-1];
263+
264+
/* Add in number of days left in month for date1. */
265+
days+=day_tab[isleap (date1->year)][date1->month-1]-date1->day;
266+
267+
/* Add in day of month of date2. */
268+
days+=date2->day;
269+
270+
return (days);
271+
}
272+
273+
/* Add a number of days to a date, giving a new date.
274+
Must handle both positive and negative numbers of days. */
275+
int4
276+
date_pli(int4dateVal,int32days)
277+
{
278+
DateADT*date1= (DateADT*)&dateVal;
279+
/* Use separate day variable because date1->day is a narrow type. */
280+
int32day=date1->day+days;
281+
282+
if (days>0)
283+
{
284+
/* Loop as long as day has wrapped around end of month. */
285+
while (day>day_tab[isleap (date1->year)][date1->month-1])
286+
{
287+
day-=day_tab[isleap (date1->year)][date1->month-1];
288+
if (++date1->month>12)
289+
{
290+
/* Month wrapped around. */
291+
date1->month=1;
292+
++date1->year;
293+
}
294+
}
295+
}
296+
else
297+
{
298+
/* Loop as long as day has wrapped around beginning of month. */
299+
while (day<1)
300+
{
301+
/* Decrement month first, because a negative day number
302+
should be held as relative to the previous month's end. */
303+
if (--date1->month<1)
304+
{
305+
/* Month wrapped around. */
306+
date1->month=12;
307+
--date1->year;
308+
}
309+
310+
day+=day_tab[isleap (date1->year)][date1->month-1];
311+
}
312+
}
313+
date1->day=day;
314+
315+
return (dateVal);
316+
}
317+
318+
/* Subtract a number of days from a date, giving a new date. */
319+
int4
320+
date_mii(int4dateVal,int32days)
321+
{
322+
return (date_pli (dateVal,-days));
323+
}
324+
227325
/*****************************************************************************
228326
* Time ADT
229327
*****************************************************************************/

‎src/include/catalog/pg_aggregate.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_aggregate.h,v 1.2 1996/10/31 09:47:04 scrappy Exp $
10+
* $Id: pg_aggregate.h,v 1.3 1996/11/14 21:39:07 scrappy Exp $
1111
*
1212
* NOTES
1313
* 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_
101101
DATA(insertOID=0 (maxPGUIDint2larger--2121021_null__null_ ));
102102
DATA(insertOID=0 (maxPGUIDfloat4larger--7007000700_null__null_ ));
103103
DATA(insertOID=0 (maxPGUIDfloat8larger--7017010701_null__null_ ));
104+
DATA(insertOID=0 (maxPGUIDdate_larger--1082108201082_null__null_ ));
104105

105106
DATA(insertOID=0 (minPGUIDint4smaller--2323023_null__null_ ));
106107
DATA(insertOID=0 (minPGUIDint2smaller--2121021_null__null_ ));
107108
DATA(insertOID=0 (minPGUIDfloat4smaller--7007000700_null__null_ ));
108109
DATA(insertOID=0 (minPGUIDfloat8smaller--7017010701_null__null_ ));
110+
DATA(insertOID=0 (minPGUIDdate_smaller--1082108201082_null__null_ ));
109111

110112
DATA(insertOID=0 (countPGUID-int4inc-002323_null_0 ));
111113

‎src/include/catalog/pg_operator.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_operator.h,v 1.3 1996/11/13 20:50:58 scrappy Exp $
10+
* $Id: pg_operator.h,v 1.4 1996/11/14 21:39:11 scrappy Exp $
1111
*
1212
* NOTES
1313
* 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
389389
DATA(insertOID=1096 ("<="PGUID0btf10821082161098109700date_leintltselintltjoinsel ));
390390
DATA(insertOID=1097 (">"PGUID0btf10821082161095109600date_gtintltselintltjoinsel ));
391391
DATA(insertOID=1098 (">="PGUID0btf10821082161096106500date_geintltselintltjoinsel ));
392+
DATA(insertOID=1099 ("-"PGUID0btf10821082230000date_mi-- ));
393+
DATA(insertOID=1100 ("+"PGUID0btf10822310820000date_pli-- ));
394+
DATA(insertOID=1101 ("-"PGUID0btf10822310820000date_mii-- ));
392395

393396
DATA(insertOID=1108 ("="PGUID0btt10831083161108110911101110time_eqeqseleqjoinsel ));
394397
DATA(insertOID=1109 ("<>"PGUID0btf10831083161109110800time_neneqselneqjoinsel ));

‎src/include/catalog/pg_proc.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: pg_proc.h,v 1.6 1996/11/13 20:51:01 scrappy Exp $
9+
* $Id: pg_proc.h,v 1.7 1996/11/14 21:39:14 scrappy Exp $
1010
*
1111
* NOTES
1212
* 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
727727
DATA(insertOID=1090 (date_gePGUID11ftf2f16"1082 1082"10000100foobar ));
728728
DATA(insertOID=1091 (date_nePGUID11ftf2f16"1082 1082"10000100foobar ));
729729
DATA(insertOID=1092 (date_cmpPGUID11ftf2f23"1082 1082"10000100foobar ));
730-
730+
DATA(insertOID=1093 (date_largerPGUID11ftf2f1082"1082 1082"10000100foobar ));
731+
DATA(insertOID=1094 (date_smallerPGUID11ftf2f1082"1082 1082"10000100foobar ));
732+
DATA(insertOID=1095 (date_miPGUID11ftf2f23"1082 1082"10000100foobar ));
733+
DATA(insertOID=1096 (date_pliPGUID11ftf2f1082"1082 23"10000100foobar ));
734+
DATA(insertOID=1097 (date_miiPGUID11ftf2f1082"1082 23"10000100foobar ));
731735
DATA(insertOID=1099 (time_inPGUID11ftf1f1083"0"10000100foobar ));
732736

733737
/* OIDS 1100 - 1199 */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp