|
15 | 15 | *
|
16 | 16 | *
|
17 | 17 | * IDENTIFICATION
|
18 |
| - * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.56 2000/02/16 00:59:27 tgl Exp $ |
| 18 | + * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.57 2000/02/26 23:03:12 tgl Exp $ |
19 | 19 | *
|
20 | 20 | *-------------------------------------------------------------------------
|
21 | 21 | */
|
@@ -470,9 +470,19 @@ scalargtjoinsel(Oid opid,
|
470 | 470 | * Returns "true" if successful.
|
471 | 471 | *
|
472 | 472 | * All numeric datatypes are simply converted to their equivalent
|
473 |
| - * "double" values. String datatypes are converted to a crude scale |
474 |
| - * using their first character (only if it is in the ASCII range, |
475 |
| - * to try to avoid problems with non-ASCII collating sequences). |
| 473 | + * "double" values. |
| 474 | + * |
| 475 | + * String datatypes are converted to a crude scale using their first character |
| 476 | + * (only if it is in the ASCII range, to try to avoid problems with non-ASCII |
| 477 | + * collating sequences). |
| 478 | + * |
| 479 | + * The several datatypes representing absolute times are all converted |
| 480 | + * to Timestamp, which is actually a double, and then we just use that |
| 481 | + * double value. Note this will give bad results for the various "special" |
| 482 | + * values of Timestamp --- what can we do with those? |
| 483 | + * |
| 484 | + * The several datatypes representing relative times (intervals) are all |
| 485 | + * converted to measurements expressed in seconds. |
476 | 486 | */
|
477 | 487 | bool
|
478 | 488 | convert_to_scalar(Datum value, Oid typid,
|
@@ -551,12 +561,63 @@ convert_to_scalar(Datum value, Oid typid,
|
551 | 561 | break;
|
552 | 562 | }
|
553 | 563 |
|
| 564 | + /* |
| 565 | + * Built-in absolute-time types |
| 566 | + */ |
| 567 | + case TIMESTAMPOID: |
| 568 | + *scaleval = * ((Timestamp *) DatumGetPointer(value)); |
| 569 | + return true; |
| 570 | + case ABSTIMEOID: |
| 571 | + *scaleval = * abstime_timestamp(value); |
| 572 | + return true; |
| 573 | + case DATEOID: |
| 574 | + *scaleval = * date_timestamp(value); |
| 575 | + return true; |
| 576 | + |
| 577 | + /* |
| 578 | + * Built-in relative-time types |
| 579 | + */ |
| 580 | + case INTERVALOID: |
| 581 | + { |
| 582 | + Interval *interval = (Interval *) DatumGetPointer(value); |
| 583 | + |
| 584 | + /* |
| 585 | + * Convert the month part of Interval to days using assumed |
| 586 | + * average month length of 365.25/12.0 days. Not too accurate, |
| 587 | + * but plenty good enough for our purposes. |
| 588 | + */ |
| 589 | + *scaleval = interval->time + |
| 590 | + interval->month * (365.25/12.0 * 24.0 * 60.0 * 60.0); |
| 591 | + return true; |
| 592 | + } |
| 593 | + case RELTIMEOID: |
| 594 | + *scaleval = (RelativeTime) DatumGetInt32(value); |
| 595 | + return true; |
| 596 | + case TINTERVALOID: |
| 597 | + { |
| 598 | + TimeInterval interval = (TimeInterval) DatumGetPointer(value); |
| 599 | + |
| 600 | + if (interval->status != 0) |
| 601 | + { |
| 602 | + *scaleval = interval->data[1] - interval->data[0]; |
| 603 | + return true; |
| 604 | + } |
| 605 | + break; |
| 606 | + } |
| 607 | + case TIMEOID: |
| 608 | + *scaleval = * ((TimeADT *) DatumGetPointer(value)); |
| 609 | + return true; |
| 610 | + |
554 | 611 | default:
|
555 | 612 | {
|
556 | 613 | /*
|
557 | 614 | * See whether there is a registered type-conversion function,
|
558 | 615 | * namely a procedure named "float8" with the right signature.
|
559 | 616 | * If so, assume we can convert the value to the numeric scale.
|
| 617 | + * |
| 618 | + * NOTE: there are no such procedures in the standard distribution, |
| 619 | + * except with argument types that we already dealt with above. |
| 620 | + * This code is just here as an escape for user-defined types. |
560 | 621 | */
|
561 | 622 | Oid oid_array[FUNC_MAX_ARGS];
|
562 | 623 | HeapTuple ftup;
|
|
0 commit comments