当前位置:网站首页>Chapter IV data type (III)

Chapter IV data type (III)

2022-06-10 18:55:00 yaoxin521123

Chapter four data type ( 3、 ... and )

date 、 Time 、PosixTime And timestamp data types

Date can be defined 、 Time and timestamp data types , And pass the standard SQL Date and time functions convert date and time stamps to and from each other . for example , have access to CURRENT_DATE or CURRENT_TIMESTAMP As input to fields defined with this data type , Or use DATEADDDATEDIFFDATENAME or DATEPART To manipulate the date value stored with this data type .

Data type class %Library.Date%Library.Time%Library.PosixTime%Library.TimeStamp and %MV.Date about SqlCategory The way to deal with it is as follows :

  1. %Library.Date Class and logical value are +$HOROLOG$HOROLOG The date part of ) Any user-defined data type class of should use DATE As SqlCategory. By default ,DATE And corresponding %Library.Date Data types only accept positive integers ,0 representative 1840-12-31. Support earlier than 1840-12-31 Date , The data type must be defined in the table as %Library.Date(MINVAL=-nnn) The date field for , among MINVAL It's from 1840-12-31 The maximum number of negative days to count down is -672045 (0001-01-01). %Library.Date You can store date values as -672045 To 2980013 Unsigned or negative integer in the range . Date values can be entered as follows :
  • Logical mode accepts +HOROLOG An integer value , for example 65619(2020 year 8 month 28 Japan ).
  • The display mode uses DisplayToLogical() Transformation method . It accepts the date in the display format of the current locale , for example “8/28/2020”. It also accepts logical date values (+HOROLOG An integer value ).
  • ODBC Mode use ODBCToLogical() Transformation method . It accepts ODBC Date in standard format , for example “2020–08–28”. It also accepts logical date values (+HOROLOG An integer value ).
  1. %Library.Time Class and any logical values are $PIECE($HOROLOG,”,”,2)$HOROLOG The time part of ) All user-defined data type classes should use TIME As SqlCategory. %Library.Time Store the time value as 0 To 86399 Unsigned integer in range ( The number of seconds since midnight ). The time value can be entered as follows :
  • Logical mode accepts $PIECE($HOROLOG,”,”,2) An integer value , for example 84444 (23:27:24).
  • The display mode uses DisplayToLogical() Transformation method . It accepts the display format of the current locale , for example “23:27:24”.
  • ODBC Mode use ODBCToLogical() Transformation method . It accepts ODBC Standard format time , for example “23:27:24”. It also accepts logical time values (0 To 86399 Range of integers ).

TIME Support decimals and seconds , Therefore, this data type can also be used for HH:MI:SS.FF To the precision specified by the user (F) Decimal digit , At most 9. To support decimal seconds , Please set up PRECISION Range . for example ,TIME(0) (%Time(PRECISION=0)) Round to the nearest second ;TIME(2) (%Time(PRECISION=2)) take ( Or zero fill ) Rounded to two decimal places of precision .

If the supplied data also specifies precision ( for example ,CURRENT_TIME(3)), Then the stored decimal places are as follows :

  • If TIME Precision not specified , And the data specifies the precision , The accuracy of the data is used .
  • If TIME Precision is not specified and the data does not specify precision , Then use the time precision configured in the system scope .
  • If TIME Precision is specified but the data does not specify precision , The time precision configured in the system range is used as the data precision .
  • If TIME The precision is specified and the data precision is less than TIME precision , Data precision is used .
  • If TIME The precision is specified and the data precision is greater than TIME precision , Then use TIME precision .

SQL Metadata reports decimal places of time precision as “scale”; It USES “precision precision ” The total length of data . Use TIME The field report precision and scale metadata of the data type are as follows :TIME(0)(%Time(PRECISION=0)) The metadata precision of is 8 (nn:nn:nn), The ratio is 0.TIME(2 ) (%Time(PRECISION=2)) The metadata precision of is 11 (nn:nn:nn.ff), The ratio is 2.TIME (%Time or %Time(PPRECISION="") Use its decimal second precision from the data provided , Therefore, the metadata precision is 18 And undefined proportions .

  1. %Library.PosixTime Class and any signed with encoding 64 User defined data type classes for bit integer logical values should use POSIXTIME As SqlCategory. %PosixTime It's from 1970–01–01 00:00:00 Seconds since ( And decimals and seconds ) Computed encoding timestamp . The time stamp after this date is positive %PosixTime Value representation , The timestamp before this date is negative %PosixTime Value representation . %PosixTime Support the most 6 Decimal second of precision . %PosixTime The earliest supported date is 0001-01-01 00:00:00, Its logical value is -6979664624441081856. The last supported date is 9999-12-3123:59:59.999999, Its logical value is 1406323805406846975.

because %PosixTime Values are always encoded by 64 Bit integers represent , So it can always be clearly distinguished from %Date or %TimeStamp value . for example ,1970–01–01 00:00:00 Of %PosixTime The value is 1152921504606846976,2017–01–01 00:00:00 Of %PosixTime The value is 1154404733406846976,1969–12–01 Of %PosixTime value 00:00:00 yes -6917531706041081856.

%PosixTime Than %TimeStamp preferable , Because it's better than %TimeStamp Data types take up less disk space and memory , And provide more than %TimeStamp Better performance .

have access to ODBC Display mode integration %PosixTime and %TimeStamp value :

  • %PosixTime and %TimeStamp The logical schema values of the data types are completely different :%PosixTime It's a signed integer ,%TimeStamp Is included ODBC Format timestamp string .
  • Display mode :%PosixTime Displays the current locale Time and date format parameters ( for example 02/22/2018 08:14:11); %TimeStamp Is shown as ODBC Format timestamp .
  • ODBC Pattern :%PosixTime and %TimeStamp Are shown as ODBC Format timestamp . The decimal places of precision may be different .

have access to TO_POSIXTIME Function or TOPOSIXTIME() Methods will %TimeStamp Value to %PosixTime. have access to IsValid() Method to determine whether the value is valid %PosixTime value .

  1. %Library.TimeStamp Class and anything with YYYY-MM-DD HH:MI:SS.FF User defined data type classes of logical values should use TIMESTAMP As SqlCategory. Please note that ,%Library.TimeStamp The maximum accuracy of comes from the accuracy of the system platform , At most 9 Decimal second , and %Library.PosixTime The maximum accuracy of is 6 position . therefore , On some platforms ,%Library.TimeStamp Maybe it's better than %Library.PosixTime More precise . %Library.TimeStamp Normalization will automatically exceed the precision of 9 The input value of bit is truncated to 9 Decimal second .
  2. %Library.DateTime yes %Library.TimeStamp Subclasses of . It defines a named DATEFORMAT Type parameter of , It covers DisplayToLogical() and OdbcToLogical() Method to handle TSQL Applications are accustomed to imprecise date and time entry .
  3. %MV.Date class , Or anything with $HOROLOG-46385 User defined data type class for logical date values , You should use MVDATE As SqlCategory.
  4. The user-defined date data type that is not suitable for any of the above logical values should be set to SqlCategory Defined as DATE, And provide... In the data type class LogicalToDate() Method to convert a user-defined logical date value to %Library.Date Logical value sum DateToLogical() Method , Is used to %Library.Date The logical value is converted to a user-defined logical date value .
  5. The user-defined time data type that is not suitable for any of the above logical values shall be set to the SqlCategory Defined as TIME, And provide... In the data type class LogicalToTime() Method to convert a user-defined logical time value to %Library.Time Logical value sum TimeToLogical() Method , Is used to %Library.Time The logical value is converted to a user-defined logical time value .
  6. The user-defined timestamp data type that is not suitable for any of the above logical values shall be changed to the SqlCategory Defined as TIMESTAMP, And provide... In the data type class LogicalToTimeStamp() Method to convert a user-defined logical timestamp value to %Library.TimeStamp Logical value sum TimeStampToLogical() Method , Is used to %Library.TimeStamp The logical value is converted to a user-defined logical timestamp value .

have access to =, <>,>, < The operator will POSIXTIME And DATE or TIMESTAMP Value comparison .

Will be FMTIMESTAMP Category values and DATE When comparing category values , IRIS In comparing it with DATE No comparison will be made from FMTIMESTAMP Remove time from value . This is compared with TIMESTAMP And DATE Value and comparison TIMESTAMP And MVDATE Values behave the same . It also works with other SQL The way vendors compare timestamps and dates is compatible . This means when using SQL equal (=) Operator ,FMTIMESTAMP 320110202.12 and DATE 62124 The comparison of is equal . The application must put FMTIMESTAMP Value to DATE or FMDATE Value to compare only the date portion of the value .

1840 year 12 month 31 The date before

The date usually consists of DATE Data type or TIMESTAMP Data type means .

DATE The data type is $HOROLOG Format storage date , As from 1840 year 12 month 31 A positive integer number of days from any start date of the day . By default , Dates can only be positive integers (MINVAL=0) Express , It corresponds to 1840 year 12 month 31 Japan . however , You can change %Library.Date MINVAL Type parameter to enable storage 1840 year 12 month 31 The date before . By way of MINVAL Set to negative , Can be stored 12 month 31 The date before , 1840 Is a negative integer . The earliest allowed MINVAL The value is -672045. This corresponds to the second 1 year (CE) Of 1 month 1 Japan . DATE The data type cannot represent BCE( Also known as BC) date .

TIMESTAMP The default data type is 1840–12–31 00:00:00 As the earliest allowed timestamp . however , You can change MINVAL Parameters to define which can store 1840 year 12 month 31 Field or attribute of the date before the day . for example ,MyTS %Library.TimeStamp(MINVAL='1492-01-01 00:00:00'). The earliest allowed MINVAL The value is 0001–01–01 00:00:00. This corresponds to the second 1 year (CE) Of 1 month 1 Japan . %TimeStamp The data type cannot represent BCE( Also known as BC) date .

Be careful : Please note that , These date calculations do not take into account the reform of the Gregorian calendar (1582 year 10 month 15 Issued on , But it was not until the 1752 It was adopted in England and its colonies in ) Date change caused by .

You can redefine the minimum date for the locale , As shown below :

	s oldMinDate = ##class(%SYS.NLS.Format).GetFormatItem("DATEMINIMUM")
	if oldMinDate = 0 {
    
		d ##class(%SYS.NLS.Format).SetFormatItem("DATEMINIMUM",-672045)
		s newMinDate = ##class(%SYS.NLS.Format).GetFormatItem("DATEMINIMUM")
		w "Changed earliest date to ",newMinDate
	} else {
     
		w "Earliest date was already reset to ",oldMinDate
	}

The above example takes the locale's MINVAL Set to the earliest date allowed (1/1/01).

Be careful :IRIS Using with negative logic... Is not supported DATE Julian date of value (%Library.Date value ,MINVAL<0). therefore , these MINVAL<0 Value and TO_CHAR The Julian date format returned by the function is incompatible .

原网站

版权声明
本文为[yaoxin521123]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206101807316134.html