当前位置:网站首页>Chapter II data type (I)

Chapter II data type (I)

2022-06-10 18:55:00 yaoxin521123

Chapter two data type ( One )

Appoint SQL Entity ( As listed ) Data types that can be included .

describe

The following topics are described here :

  • Supported by DDL Data type and its class attribute mapping table

  • Data type priority is used to select the most inclusive data type from data values with different data types

  • date 、 Time 、PosixTime And timestamp data types

    • Use SqlCategory And user-defined standards
    • Yes 1840 year 12 month 31 Configurable support for dates before
  • Support string data types 、 List data type and stream data type

  • Support ROWVERSION data type

  • IRIS Data platform ODBC / JDBC Exposed data types

  • Use the query metadata method and data type integer code to determine the data type of the column

  • Create user-defined data types

  • Handle undefined data types

  • Data type conversion function

The data type specifies the kind of values that the column can hold . In the use of CREATE TABLE or ALTER TABLE Specify the data type when defining the field . Definition SQL A field , The following table can be specified ( Left column ) Listed in the DDL data type . When specifying one of the DDL Data type , It maps to the... Listed in the right column IRIS Data type class . stay IRIS When defining fields in , You can specify DDL Data type or data type class . DDL Data type names are not case sensitive . Data type class names are case sensitive . %Library Data type classes can be defined by their full names ( for example ,%Library.String) Or short name (%String) To specify the .

They map to DDL Data types and data type classes usually provide different parameters and parameter defaults . Data type classes usually provide more information than DDL Data types have more parameters to define the allowed data values .

To view the current system data type mapping , Please go to the administration portal , Choose system management 、 To configure 、SQL And object settings 、 System DDL mapping .

 Insert picture description here

You can also define other user data types . To create or view user data type mappings , Please go to the administration portal , Choose system management 、 To configure 、SQL And object settings 、 user DDL mapping .

DDL Data type table

DDL Data TypeCorresponding IRIS Data Type Class
BIGINT%Library.BigInt (MAXVAL=9223372036854775807, MINVAL=-9223372036854775807) If BIGINT Columns can contain both NULL And minimal negative numbers , The index empty tag needs to be redefined to support the standard index collation .
BIGINT(%1)%Library.BigInt %1 Be ignored . amount to BIGINT. Provide MySQL Compatibility .
BINARY%Library.Binary(MAXLEN=1)
BINARY(%1)%Library.Binary(MAXLEN=%1)
BINARY VARYING%Library.Binary(MAXLEN=1)
BINARY VARYING(%1)%Library.Binary(MAXLEN=%1)
BIT%Library.Boolean .
CHAR%Library.String(MAXLEN=1)
CHAR(%1)%Library.String(MAXLEN=%1)
CHAR VARYING%Library.String(MAXLEN=1)
CHAR VARYING(%1)%Library.String(MAXLEN=%1)
CHARACTER%Library.String(MAXLEN=1)
CHARACTER VARYING%Library.String(MAXLEN=1)
CHARACTER VARYING(%1)%Library.String(MAXLEN=%1)
CHARACTER(%1)%Library.String(MAXLEN=%1)
DATE%Library.Date
DATETIME%Library.DateTime
DATETIME2%Library.DateTime
DEC%Library.Numeric MAXVAL=999999999999999, MINVAL=-999999999999999, SCALE=0.
DEC(%1)%Library.Numeric One 64 Bit signed integer . If %1 Less than 19, be MAXVAL and MINVAL yes %1 digit . for example ,DEC(8) MAXVAL=99999999,MINVAL=-99999999,SCALE=0. %1 The most significant value of is 19; %1 Greater than 19 There will be no mistakes , But the default is 19. If %1 by 19 Or bigger :MAXVAL=9223372036854775807,MINVAL=-9223372036854775808,SCALE=0.
DEC(%1,%2)%Library.Numeric (`MAXVAL=<
DECIMAL%Library.Numeric MAXVAL=999999999999999, MINVAL=-999999999999999, SCALE=0.
DECIMAL(%1)%Library.Numeric One 64 Bit signed integer . If %1 Less than 19, be MAXVAL and MINVAL yes %1 digit . for example ,DECIMAL(8) MAXVAL=99999999,MINVAL=-99999999,SCALE=0. %1 The most significant value of is 19; %1 Greater than 19 There will be no mistakes , But the default is 19. If %1 by 19 Or bigger :MAXVAL=9223372036854775807,MINVAL=-9223372036854775808,SCALE=0.
DECIMAL(%1,%2)%Library.Numeric (`MAXVAL=<
DOUBLE%Library.Double This is a IEEE Floating point standard . With this data type SQL The default precision returned by the column is 20.
DOUBLE PRECISION%Library.Double This is a IEEE Floating point standard . With this data type SQL The default precision returned by the column is 20.
FLOAT Have been abandoned — %Library.Double This is a IEEE Floating point standard . With this data type SQL The default precision returned by the column is 20. FLOAT(%1) Have been abandoned — %Library.Double This is a IEEE Floating point standard . With this data type SQL The default precision returned by the column is 20.
IMAGE%Stream.GlobalBinary
INT%Library.Integer (MAXVAL=2147483647, MINVAL=-2147483648)
INT(%1)%Library.Integer (MAXVAL=2147483647, MINVAL=-2147483648). %1 Be ignored . amount to INT. Provide MySQL Compatibility .
INTEGER%Library.Integer (MAXVAL=2147483647, MINVAL=-2147483648)
LONG%Stream.GlobalCharacter
LONG BINARY%Stream.GlobalBinary
LONG RAW%Stream.GlobalBinary
LONGTEXT%Stream.GlobalCharacter Equivalent to LONG. Provide MySQL Compatibility .
LONG VARCHAR%Stream.GlobalCharacter
LONG VARCHAR(%1)%Stream.GlobalCharacter The %1 is ignored.
LONGVARBINARY%Stream.GlobalBinary
LONGVARBINARY(%1)%Stream.GlobalBinary The %1 is ignored.
LONGVARCHAR%Stream.GlobalCharacter
LONGVARCHAR(%1)%Stream.GlobalCharacter The %1 is ignored.
MEDIUMINT%Library.Integer(MAXVAL=8388607,MINVAL=-8388608) Provide MySQL Compatibility .
MEDIUMINT(%1)%Library.Integer(MAXVAL=8388607,MINVAL=-8388608) %1 Be ignored . Provide MySQL Compatibility .
MEDIUMTEXT%Stream.GlobalCharacter
MONEY%Library.Currency(MAXVAL=922337203685477.5807, MINVAL=-922337203685477.5808, SCALE=4)
NATIONAL CHAR%Library.String(MAXLEN=1)
NATIONAL CHAR(%1)%Library.String(MAXLEN=%1)
NATIONAL CHAR VARYING%Library.String(MAXLEN=1)
NATIONAL CHAR VARYING(%1)%Library.String(MAXLEN=%1)
NATIONAL CHARACTER%Library.String(MAXLEN=1)
NATIONAL CHARACTER(%1)%Library.String(MAXLEN=%1)
NATIONAL CHARACTER VARYING%Library.String(MAXLEN=1)
NATIONAL CHARACTER VARYING(%1)%Library.String(MAXLEN=%1)
NATIONAL VARCHAR%Library.String(MAXLEN=1)
NATIONAL VARCHAR(%1)%Library.String(MAXLEN=%1)
NCHAR%Library.String(MAXLEN=1)
NCHAR(%1)%Library.String(MAXLEN=%1)
NTEXT%Stream.GlobalCharacter
NUMBER%Library.Numeric One 64 Bit signed integer . (MAXVAL=9223372036854775807, MINVAL=-9223372036854775808, SCALE=0)
NUMBER(%1)%Library.Numeric One 64 Bit signed integer . If %1 Less than 19, be MAXVAL and MINVAL yes %1 digit . for example ,NUMBER(8) MAXVAL=99999999,MINVAL=-99999999,SCALE=0. %1 The most significant value of is 19; %1 Greater than 19 There will be no mistakes , But the default is 19. If %1 by 19 Or bigger :MAXVAL=9223372036854775807,MINVAL=-9223372036854775808,SCALE=0.
NUMBER(%1,%2)%Library.Numeric (`MAXVAL=<
NUMERIC%Library.Numeric MAXVAL=999999999999999, MINVAL=-999999999999999, SCALE=0.
NUMERIC(%1)%Library.Numeric One 64 Bit signed integer . If %1 Less than 19, be MAXVAL and MINVAL yes %1 digit . for example ,NUMERIC(8) MAXVAL=99999999,MINVAL=-99999999,SCALE=0. %1 The most significant value of is 19; %1 Greater than 19 There will be no mistakes , But the default is 19. If %1 by 19 Or bigger :MAXVAL=9223372036854775807,MINVAL=-9223372036854775808,SCALE=0.
NUMERIC(%1,%2)%Library.Numeric (`MAXVAL=<
NVARCHAR%Library.String(MAXLEN=1)
NVARCHAR(%1)%Library.String(MAXLEN=%1)
NVARCHAR(%1,%2)%Library.String(MAXLEN=%1)
NVARCHAR(MAX)%Stream.GlobalCharacter Equivalent to LONGVARCHAR. Provide TSQL Compatibility .
POSIXTIME%Library.PosixTime MAXVAL=1406323805406846975, MINVAL=-6979664624441081856, SCALE=0.
RAW(%1)%Library.Binary(MAXLEN=%1) REAL Have been abandoned — %Library.Double This is a IEEE Floating point standard . With this data type SQL The default precision returned by the column is 20.
ROWVERSION%Library.RowVersion(MAXVAL=9223372036854775807, MINVAL=1) System allocated sequential integer .
SERIAL%Library.Counter System-generated: (MAXVAL=9223372036854775807, MINVAL=1). User-supplied: (MAXVAL=9223372036854775807, MINVAL=-9223372036854775807)
SMALLDATETIME%Library.DateTime MAXVAL=’2079-06-06 23:59:59’; MINVAL=’1900-01-01 00:00:00’)
SMALLINT%Library.SmallInt (MAXVAL=32767, MINVAL=-32768)
SMALLINT(%1)%Library.SmallInt %1 Be ignored . amount to SMALLINT. Provide MySQL Compatibility .
SMALLMONEY%Library.Currency SCALE=4
SYSNAME%Library.String(MAXLEN=128)
TEXT%Stream.GlobalCharacter
TIME%Library.Time
TIME(%1)%Library.Time( precision =%1). PRECISION Is the number of decimal seconds , A between 0 To 9 The integer value between .
TIMESTAMP%Library.PosixTime
TIMESTAMP2%Library.TimeStamp
TINYINT%Library.TinyInt (MAXVAL=127, MINVAL=-128)
TINYINT(%1)%Library.TinyInt %1 Be ignored . amount to TINYINT. Provide MySQL Compatibility .
UNIQUEIDENTIFIER)%Library.UniqueIdentifier
VARBINARY)%Library.Binary(MAXLEN=1)
VARBINARY(%1))%Library.Binary(MAXLEN=%1)
VARCHAR )%Library.String(MAXLEN=1)
VARCHAR(%1) )%Library.String(MAXLEN=%1)
VARCHAR(%1,%2))%Library.String(MAXLEN=%1)
VARCHAR2(%1))%Library.String(MAXLEN=%1)
VARCHAR(MAX))%Stream.GlobalCharacter Equivalent to LONGVARCHAR. Available only TSQL Compatibility .

Important note : Each... Shown above DDL or IRIS Data type expressions are actually a continuous string . These strings may contain space characters , But it usually doesn't contain any kind of space . For easy reading , There are some blanks in this table .

Appoint MAXLEN

  • nothing MAXLEN: No, MAXLEN The value field can take values of any length , Maximum string length . To define the maximum length string field , Please specify VARCHAR(''), This will create a data type of %Library.String(MAXLEN="") Properties of . VARCHAR() The created data type is %Library.String(MAXLEN=1) Properties of . To define no MAXLEN Binary field of value , Please specify VARBINARY(''), This will create a data type of %Library.Binary(MAXLEN="") Properties of . VARBINARY() The created data type is %Library.Binary(MAXLEN=1) Properties of .
  • Big MAXLEN Have a big MAXLEN The value field only allocates the space required for the actual data value . Appoint %Library.String Data type , designated MAXLEN The value does not have to correspond closely to the actual size of the data . If the field value is “ABC”, Use only disks 、 So much space in the global buffer and private process memory . Even using MAXLEN=1000 Declare this field , Private process memory will not allocate so much space for this field . Allocate memory only for the actual size of the field value , Regardless of the length of the declaration .

Too much MAXLEN Values may affect ODBC Applications . ODBC The application tries to determine the size of the required fields based on the metadata from the server , Therefore, the application may allocate more buffer space than it actually needs . For this reason , Provides system wide defaults ODBC VARCHAR Maximum length 4096; The system wide default settings can be configured using the management portal : Select configuration from system management , And then choose SQL And object settings , And then choose SQL. View or set up VARCHAR The default length of the option . To determine the current settings , Please call $SYSTEM.SQL.CurrentSettings(). ODBC Driver from TCP The buffer takes the data and converts it into an application buffer , therefore MAXLEN Size doesn't affect our ODBC client .

Too much MAXLEN The value should not affect JDBC Applications . Java and .Net No application allocated buffer . The client allocates only what is required to save the data as a native type .

Accuracy and range

NUMERIC(6,2) Equal value data types have two integer values (p,s) Precision and scale . These are mapped to ObjectScript %Library Class data type . stay SQL When specified in the data type , The following applies to Windows System ( The maximum value may be different on other systems ):

  • Precision precision :0 To 19+s( contain ) Integer between . This value determines the maximum and minimum allowable values . This is usually the total number of digits in a number ; however , Its exact value is determined by %Library Class data type mapping determines . The maximum integer value is 9223372036854775807. Greater than 19+s The default precision of is 19+s.
  • Scale: An integer , Specify the maximum decimal allowed ( decimal ) digit . It can be a positive integer 、0 Or negative integer . If s Greater than or equal to p, Only decimals are allowed , actual p Value ignored . The maximum proportion allowed is 18, Corresponding to 0.999999999999999999. Greater than 18 The default scale is 18.

The following example shows the maximum values for different combinations of precision and scale :

ClassMethod PrecisionScale()
{
    
	for i = 0 : 1 : 6 {
    
		w "Max for (",i,",2)=",$$maxval^%apiSQL(i,2),!
	}
}

DHC-APP>d ##class(PHA.TEST.SQLFunction).PrecisionScale()
Max for (0,2)=.99
Max for (1,2)=.99
Max for (2,2)=.99
Max for (3,2)=9.99
Max for (4,2)=99.99
Max for (5,2)=999.99
Max for (6,2)=9999.99
原网站

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