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

Commitaff830a

Browse files
committed
Add date and time datatype handling to convert_to_scalar. (I was waiting
for Thomas to do the datetime consolidation before touching this, butit's done now...)
1 parentbaeef0e commitaff830a

File tree

1 file changed

+65
-4
lines changed

1 file changed

+65
-4
lines changed

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

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* 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 $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -470,9 +470,19 @@ scalargtjoinsel(Oid opid,
470470
* Returns "true" if successful.
471471
*
472472
* 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.
476486
*/
477487
bool
478488
convert_to_scalar(Datumvalue,Oidtypid,
@@ -551,12 +561,63 @@ convert_to_scalar(Datum value, Oid typid,
551561
break;
552562
}
553563

564+
/*
565+
* Built-in absolute-time types
566+
*/
567+
caseTIMESTAMPOID:
568+
*scaleval=* ((Timestamp*)DatumGetPointer(value));
569+
return true;
570+
caseABSTIMEOID:
571+
*scaleval=*abstime_timestamp(value);
572+
return true;
573+
caseDATEOID:
574+
*scaleval=*date_timestamp(value);
575+
return true;
576+
577+
/*
578+
* Built-in relative-time types
579+
*/
580+
caseINTERVALOID:
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+
caseRELTIMEOID:
594+
*scaleval= (RelativeTime)DatumGetInt32(value);
595+
return true;
596+
caseTINTERVALOID:
597+
{
598+
TimeIntervalinterval= (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+
caseTIMEOID:
608+
*scaleval=* ((TimeADT*)DatumGetPointer(value));
609+
return true;
610+
554611
default:
555612
{
556613
/*
557614
* See whether there is a registered type-conversion function,
558615
* namely a procedure named "float8" with the right signature.
559616
* 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.
560621
*/
561622
Oidoid_array[FUNC_MAX_ARGS];
562623
HeapTupleftup;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp