当前位置:网站首页>Chapter IV data type (III)
Chapter IV data type (III)
2022-06-10 18:55:00 【yaoxin521123】
List of articles
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 DATEADD、DATEDIFF、DATENAME 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 :
%Library.DateClass and logical value are+$HOROLOG($HOROLOGThe date part of ) Any user-defined data type class of should useDATEAsSqlCategory. By default ,DATEAnd corresponding%Library.DateData types only accept positive integers ,0representative1840-12-31. Support earlier than1840-12-31Date , The data type must be defined in the table as%Library.Date(MINVAL=-nnn)The date field for , amongMINVALIt's from1840-12-31The maximum number of negative days to count down is-672045 (0001-01-01).%Library.DateYou can store date values as-672045To2980013Unsigned or negative integer in the range . Date values can be entered as follows :
- Logical mode accepts
+HOROLOGAn integer value , for example65619(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 (+HOROLOGAn 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 (+HOROLOGAn integer value ).
%Library.TimeClass and any logical values are$PIECE($HOROLOG,”,”,2)($HOROLOGThe time part of ) All user-defined data type classes should useTIMEAsSqlCategory.%Library.TimeStore the time value as0To86399Unsigned 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 example84444 (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 (0To86399Range 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
TIMEPrecision not specified , And the data specifies the precision , The accuracy of the data is used . - If
TIMEPrecision is not specified and the data does not specify precision , Then use the time precision configured in the system scope . - If
TIMEPrecision is specified but the data does not specify precision , The time precision configured in the system range is used as the data precision . - If
TIMEThe precision is specified and the data precision is less thanTIMEprecision , Data precision is used . - If
TIMEThe precision is specified and the data precision is greater thanTIMEprecision , Then useTIMEprecision .
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 .
%Library.PosixTimeClass and any signed with encoding64User defined data type classes for bit integer logical values should use POSIXTIME AsSqlCategory.%PosixTimeIt's from1970–01–01 00:00:00Seconds since ( And decimals and seconds ) Computed encoding timestamp . The time stamp after this date is positive%PosixTimeValue representation , The timestamp before this date is negative %PosixTime Value representation .%PosixTimeSupport the most6Decimal second of precision .%PosixTimeThe earliest supported date is0001-01-01 00:00:00, Its logical value is-6979664624441081856. The last supported date is9999-12-3123:59:59.999999, Its logical value is1406323805406846975.
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 :
%PosixTimeand%TimeStampThe logical schema values of the data types are completely different :%PosixTimeIt's a signed integer ,%TimeStampIs included ODBC Format timestamp string .- Display mode :
%PosixTimeDisplays the currentlocaleTime and date format parameters ( for example02/22/2018 08:14:11);%TimeStampIs shown as ODBC Format timestamp . - ODBC Pattern :
%PosixTimeand%TimeStampAre 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 .
%Library.TimeStampClass and anything withYYYY-MM-DD HH:MI:SS.FFUser defined data type classes of logical values should useTIMESTAMPAsSqlCategory. Please note that ,%Library.TimeStampThe maximum accuracy of comes from the accuracy of the system platform , At most9Decimal second , and%Library.PosixTimeThe maximum accuracy of is6position . therefore , On some platforms ,%Library.TimeStampMaybe it's better than%Library.PosixTimeMore precise .%Library.TimeStampNormalization will automatically exceed the precision of9The input value of bit is truncated to9Decimal second .%Library.DateTimeyes%Library.TimeStampSubclasses of . It defines a namedDATEFORMATType parameter of , It coversDisplayToLogical()andOdbcToLogical()Method to handle TSQL Applications are accustomed to imprecise date and time entry .%MV.Dateclass , Or anything with$HOROLOG-46385User defined data type class for logical date values , You should useMVDATEAsSqlCategory.- The user-defined date data type that is not suitable for any of the above logical values should be set to
SqlCategoryDefined asDATE, And provide... In the data type classLogicalToDate()Method to convert a user-defined logical date value to%Library.DateLogical value sumDateToLogical()Method , Is used to%Library.DateThe logical value is converted to a user-defined logical date value . - The user-defined time data type that is not suitable for any of the above logical values shall be set to the
SqlCategoryDefined asTIME, And provide... In the data type classLogicalToTime()Method to convert a user-defined logical time value to%Library.TimeLogical value sumTimeToLogical()Method , Is used to%Library.TimeThe logical value is converted to a user-defined logical time value . - The user-defined timestamp data type that is not suitable for any of the above logical values shall be changed to the
SqlCategoryDefined asTIMESTAMP, And provide... In the data type classLogicalToTimeStamp()Method to convert a user-defined logical timestamp value to%Library.TimeStampLogical value sumTimeStampToLogical()Method , Is used to%Library.TimeStampThe 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 .
边栏推荐
- 商业智能BI如何帮企业降低人力、时间和管理成本?
- In 2021, the world's top ten analog IC suppliers: Ti ranked first, and skyworks' revenue growth was the highest
- muduo源码剖析——以三个切片浅析muduo库代码设计的严谨性、高效性与灵活性
- 用基础比率重写清晰的贝叶斯公式
- 什么是商业智能BI,谈谈商业智能BI的定义与作用
- 【QNX Hypervisor 2.2 用户手册】3.2.1 VM配置语法
- JS Touch
- uniapp 原生js实现公历转农历
- Stream流的常用方法-Lambder
- Adobe Premiere基础-素材嵌套(制作抖音结尾头像动画)(九)
猜你喜欢

5. golang generics and reflection

Huawei cloud Kunpeng devkit code migration practice

Adobe Premiere foundation - time remapping (10)

SaleSmartly | 再添新渠道Slack,助你拉近客户关系

Metadata management, the basic construction of enterprises in the digital era
![[database] differences among structured data, unstructured data and semi-structured data](/img/1f/fe9e0ad982d281dcb6e1236be5f239.jpg)
[database] differences among structured data, unstructured data and semi-structured data

Data URL

uniapp uview 框架的form表单,输入校验手机号、校验微信号

In the introductory study of data visualization, we should be alert to pitfalls and misunderstandings and grasp key nodes

Common methods of stream flow lambder
随机推荐
Enterprise data quality management: how to evaluate data quality?
Data URL
SQL 函数
Huawei cloud Kunpeng devkit code migration practice
Adobe Premiere Foundation (the last step of video subtitle adding) (6)
Adobe Premiere基础-时间重映射(十)
Adobe Premiere基础(动画制作)(七)
How to transform digital transformation? Which way?
[Code] neural symbol generation machine
Custom types: structural bodies
vcsa7u3c安装教程
MySQL索引失效场景
[kuangbin] topic 12 basic DP1
Rewrite clear Bayesian formula with base ratio
AD18器件库导入简介
第一章 SQL操作符
【接口教程】EasyCVR如何通过接口设置平台级联?
阵列信号处理仿真之四——Z变换分析阵列多项式
第二章 数据类型(一)
Adobe Premiere foundation - time remapping (10)