When managing database tables, it is important to know the datatype system provided by SAP HANA on the SQL level. These are outlined in the tables below.
The following table lists the numerical SQL datatypes supported by SAP HANA.
Numerical Datatypes
| | Data Type | Remark |
|---|
| Integers | TINYINT | unsigned, 8-bit integer values |
| SMALLINT | signed, 16-bit integer values |
| INTEGER | signed, 32-bit integer values |
| BIGINT | signed, 64-bit integer values |
| Real numbers | DECIMAL(p,s) | Fixed-point decimal number with total number of digits p (precision) and s (scale) digits right of the decimal point (fractional digits). |
| SMALLDECIMAL | Floating point number with precision varying dynamically between 1 and 16 and scale between –369 and 368, respectively between 1 and 34 and scale between –6111 and 6167 |
| DECIMAL |
| REAL | 32-bit floating point number |
| DOUBLE | 64-bit floating point number |
| FLOAT(N) | 32-bit or 64-bit real number with N significant bits. 1 <= N<= 53. |
Note
DECIMAL(p,s) is suitable for storing fixed-point decimal numbers with digits in total and s fractional digits, whereas DECIMAL (without precision and scale) is used to store floating point numbers.
Since floating point numbers often cannot be represented exactly in the binary system and are rounded, you should use them with care in database tables. Especially avoid using them in WHERE clauses.
The number 1.0000259 has precision 8 and scale 7. The number 3.1415 requires at least precision 5 and scale 4 to be stored without loss of precision. Using DECIMAL(5,4) it is stored as 3.1415, using DECIMAL(8,7) as 3.1415000.
The following table lists the string-like SQL datatypes supported by SAP HANA.
String/Character Datatypes
| Data Type | Remark |
|---|
| VARCHAR(n) | Variable-length ASCII character string with maximum length n (n ≤ 5,000) |
| NVARCHAR(n) | Variable-length unicode character string with maximum length n (n ≤ 5,000) |
| ALPHANUM(n) | Variable-length alphanumeric character string with maximum length n (n ≤ 127) |
| SHORTTEXT(n) | Variable-length unicode character string based on NVARCHAR (n) with support for text- and string-search features |
The following table lists the data and time SQL datatypes supported by SAP HANA.
Datatypes for Date and Time
| Data Type | Remark |
|---|
| DATE | Consists of year, month, day '2012-05-21' |
| TIME | Consists of hour, minute, second '18:00:57' |
| SECONDDATE | Combination of data and time '2012-05-21 18:00:57' |
| TIMESTAMP | Precision: ten millionth of a second '2012-05-21 18:00:57.1234567' |
The following table lists the binary and large object SQL datatypes supported by SAP HANA.
Datatypes for Binary Data and Large Objects
| | Data Type | Remark |
|---|
| Binary Data | VARBINARY(n) | Binary data, maximum length n Bytes (n ≤ 5,000) |
| Large Objects | BLOB | Large binary data (maximum 2 GB) |
| CLOB | Long ASCII character string (maximum 2 GB) |
| NCLOB | Long unicode character string (maximum 2 GB) |
| TEXT | Long unicode character string (maximum 2 GB) based on NCLOB with support for text- and string-search features |
Datatype VARBINARY can be used to store short values in binary form, for example, UUIDs (Universally Unique IDentifiers):
1234567
INSERT INTO MyTable
VALUES ( ... TO_BINARY('Walldorf') ...);
-- Value stored in DB: 57616C6C646F7266
INSERT INTO MyTable
VALUES ( ... TO_BINARY(x'00075341500700FF') ...);
-- x'..' is a hexadecimal literal value
The term LOB datatype (LOB = large object) is used as a generic term for datatypes such as CLOB (character large object) or BLOB (binary large object).
When using LOB datatypes it is important to note the following:
LOB columns cannot be part of the primary key.
LOB columns cannot be used in the ORDER BY clause.
LOB columns cannot be used in the GROUP BY clause.
LOB columns may not be part of the JOIN condition (explicit join syntax).
LOB columns cannot be used as an argument for an aggregate function.
LOB columns cannot be used in the SELECT DISTINCT clause.
LOB columns cannot occur in a UNION statement.
LOB columns cannot be part of a database index.