TOC PREV NEXT

 

 

 

SQL Data Types


This chapter describes all of the SQL data types that PointBase supports. Data types define what type of data a column can contain. The following sections describe each PointBase data type in detail and discuss converting data types. Tables are provided at the end of the chapter to show the mappings between PointBase data types and industry standard and other common non-standard data types.

Data Types

PointBase supports the following data types for its column and parameter declarations.

CHARACTER [(length)] or CHAR [(length)]

The CHARACTER data type accepts character strings, including Unicode, of a fixed length. The length of the character string should be specified in the data type declaration; for example, CHARACTER(n) where n represents the desired length of the character string. If no length is specified during the declaration, the default length is 1.

The minimum length of the CHARACTER data type is 1 and it can have a maximum length up to the table page size. Character strings that are larger than the page size of the table can be stored as a Character Large Object (CLOB).

NOTE: CHARACTER(0) is not allowed and raises an exception.

If you assign a value to a CHARACTER column containing fewer characters than the defined length, the remaining space is filled with blanks characters. Any comparisons made to a CHARACTER column must take these trailing spaces into account.

Attempting to assign a value containing more characters than the defined length results in the truncation of the character string to the defined length. If any of the truncated characters are not blank, an error is raised.

Character String Examples:

CHAR(10) or CHARACTER(10)

'Race car'
'RACECAR'
'24865'
'1998-10-25'
'1998-10-25 ' (Blank characters are truncated)

24865
1998-10-25
'Date: 1998-10-25'

VARCHAR (length)

The VARCHAR data type accepts character strings, including Unicode, of a variable length is up to the maximum length specified in the data type declaration.

A VARCHAR declaration must include a positive integer in parentheses to define the maximum allowable character string length. For example, VARCHAR(n) can accept any length of character string up to n characters in length. The length parameter may take any value from 1 to the current table page size. Attempting to assign a value containing more characters than the defined maximum length results in the truncation of the character string to the defined length. If any of the truncated characters are not blank, an error is raised.

NOTE: VARCHAR(0) is not allowed and raises an exception.

If you need to store character strings that are longer than the current table page size, the Character Large Object (CLOB) data type should be used.

Examples

VARCHAR(10)

'Race car'
'RACECAR'
'24865'
'1998-10-25'
'1998-10-25 '

24865
1998-10-25
'Date: 1998-10-25'

BOOLEAN

The BOOLEAN data type supports the storage of two values: TRUE or FALSE. No parameters are required when declaring a BOOLEAN data type.

Use the case insensitive keywords TRUE or FALSE to assign a value to a BOOLEAN data type. Comparisons using the BOOLEAN data type should also use these keywords. If you attempt to assign any other value to a BOOLEAN data type, an error is raised.

Examples

BOOLEAN

TRUE
true
True
False

1
0
Yes
No

SMALLINT

The SMALLINT data type accepts numeric values with an implied scale of zero. It stores any integer value between the range 2^ -15 and 2^15 -1. Attempting to assign values outside this range causes an error.

If you assign a numeric value with a precision and scale to a SMALLINT data type, the scale portion truncates, without rounding.

NOTE: To store values beyond the range (2^-15) to (2^15)-1, use the INTEGER data type.

Examples

SMALLINT

-32768
0
-30.3 (digits to the right of the decimal point are truncated)
32767

-33,000,567
-32769
32768
1,897,536,000

INTEGER or INT

The INTEGER data type accepts numeric values with an implied scale of zero. It stores any integer value between the range 2^ -31 and 2^31 -1. Attempting to assign values outside this range causes an error.

If you assign a numeric value with a precision and scale to an INTEGER data type, the scale portion truncates, without rounding.

NOTE: To store integer values beyond the range (2^-31) to (2^31)-1, use the DECIMAL data type with a scale of zero.

Examples

INTEGER or INT

-2147483648
-1025
0
1025.98 (digits to the right of the decimal point are truncated)
2147483647

-1,025,234,000,367
-2147483649
2147483648
1,025,234,000,367

DECIMAL [(p[,s])] or DEC [(p[,s])]

The DECIMAL data type accepts numeric values, for which you may define a precision and a scale in the data type declaration. The precision is a positive integer that indicates the number of digits that the number will contain. The scale is a positive integer that indicates the number of these digits that will represent decimal places to the right of the decimal point. The scale for a DECIMAL cannot be larger than the precision.

DECIMAL data types can be declared in one of three different ways. The declaration of it controls how the number is presented to an SQL query, but not how it is stored.

In the above examples, p is an integer representing the precision and s is an integer representing the scale.

NOTE: If you exceed the number of digits expected to the left of the decimal point, an error is thrown. If you exceed the number of expected digits to the right of the decimal point, the extra digits are truncated.

Examples

DECIMAL(10,3)

1234567
1234567.123
1234567.1234 (Final digit is truncated)
-1234567
-1234567.123
-1234567.1234 (Final digit is truncated)

12345678
12345678.12
12345678.123
-12345678
-12345678.12
-12345678.123

NUMERIC [(p[,s])]

PointBase treats the NUMERIC data type in exactly the same way as the DECIMAL data type.

REAL

The REAL data type accepts approximate numeric values, up to a precision of 64. No parameters are required when declaring a REAL data type. If you attempt to assign a value with a precision greater than 64 an error is raised.

Examples

REAL

-2345
0
1E-3
1.245
123456789012345678901234567890

123,456,789,012,345,678,901,234,567,890,123

FLOAT(p)

The FLOAT data type accepts approximate numeric values, for which you may define a precision up to a maximum of 64. If no precision is specified during the declaration, the default precision is 64. Attempting to assign a value lager than the declared precision will cause an error to be raised.

Examples

FLOAT(8)

12345678
1.2
123.45678
-12345678
-1.2
-123.45678

123456789
123.456789
-123456789
-123.456789

DOUBLE PRECISION

The REAL data type accepts approximate numeric values, up to a precision of 64. No parameters are required when declaring a DOUBLE PRECISION data type. If you attempt to assign a value with a precision greater than 64 an error is raised.

Examples

DOUBLE PRECISION

12345678901234567890123456789012345678901234567890123456
7890

-12345678901234567890123456789012345678901234567890123456
7890

123,456,789,012,345,678,901,234,567,890,123,123,456,789,

012,345,678,901,234,567,890

-123,456,789,012,345,678,901,234,567,890,123,123,456,789,

012,345,678,901,234,567,890

DATE

The DATE data type accepts date values. No parameters are required when declaring a DATE data type. Date values should be specified in the form: YYYY-MM-DD. However, PointBase will also accept single digits entries for month and day values.

Month values must be between 1 and 12, day values should be between 1 and 31 depending on the month and year values should be between 0 and 9999.

Values assigned to the DATE data type should be enclosed in single quotes, preceded by the case insensitive keyword DATE; for example, DATE '1999-04-04'.

Examples

DATE

DATE '1999-01-01'
DATE '2000-2-2'
date '0-1-1'

DATE '1999-13-1'
date '2000-2-30'
'2000-2-27'
date 2000-2-27

TIME

The TIME data type accepts time values. No parameters are required when declaring a TIME data type. Date values should be specified in the form: HH:MM:SS. An optional fractional value can be used to represent nanoseconds.

The minutes and seconds values must be two digits. Hour values should be between zero 0 and 23, minute values should be between 00 and 59 and second values should be between 00 and 61.999999.

Values assigned to the TIME data type should be enclosed in single quotes, preceded by the case insensitive keyword TIME; for example, TIME '07:30:00'.

Examples

TIME

TIME '00:00:00'
TIME '1:00:00'
TIME '23:59:59'
time '23:59:59.99'

TIME '00:62:00'
TIME '00:3:00'
TIME '23:01'
'24:01:00'

TIMESTAMP

The TIMESTAMP data type accepts timestamp values, which are a combination of a DATE value and a TIME value. No parameters are required when declaring a TIMESTAMP data type. Timestamp values should be specified in the form: YYYY-MM-DD HH:MM:SS. There is a space separator between the date and time portions of the timestamp.

All specifications and restrictions noted for the DATE and TIME data types also apply to the TIMESTAMP data type.

Values assigned to the TIMESTAMP data type should be enclosed in single quotes, preceded by the case insensitive keyword TIMESTAMP; for example, TIMESTAMP '1999-04-04 07:30:00'.

Examples

TIMESTAMP

TIMESTAMP `1999-12-31 23:59:59.99'
TIMESTAMP `0-01-01 00:00:00'

1999-00-00 00:00:00
TIMESTAMP `1999-01-01 00:64:00'

CLOB [(length)] or CHARACTER LARGE OBJECT [(length)] or CHAR LARGE OBJECT [(length)]

The Character Large Object (CLOB) data type accepts character strings longer than those that are allowed in the CHARACTER [(length)] or VARCHAR (length) data types. The CLOB declaration uses the following syntax to specify the length of the CLOB in bytes:

n [K | M | G]

In the above syntax, n is an unsigned integer that represents the length. K, M, and G correspond to Kilobytes, Megabytes or Gigabytes, respectively. If K, M, or G is specified in addition to n, then the actual length of n is the following:

The maximum size allowed for CLOB data types is 2 gigabytes. If a length is not specified, then a default length of one byte is used. CLOB values can vary in length from one byte up to the specified length.

NOTE: The CLOB data type supports Unicode data.

BLOB [(length)] or BINARY LARGE OBJECT [(length)]

The Binary Large Object (BLOB) data type accepts binary values. The BLOB declaration uses the following syntax to specify the length in bytes:

n [K | M | G]

In the above syntax, n is an unsigned integer that represents the length. K, M, and G correspond to Kilobytes, Megabytes or Gigabytes, respectively. If K, M, or G is specified in addition to n, then the actual length of n is the following:

The maximum size allowed for BLOB data types is 2 gigabytes. If a length is not specified, then a default length of one byte is used. BLOB values can vary in length from one byte up to the specified length.

NOTE: BLOB data types cannot be used with SQL scalar functions.

Data Conversions and Assignments

The PointBase database allows two types of data conversions - implicit and explicit. An implicit data conversion is automatically performed between data types that are in the same data type family. Table 1 describes the data type families supported by PointBase. Implicit data conversions are performed as needed and are transparent to the user.

PointBase handles explicit data conversion using the SQL Scalar CAST function. This function converts a value from one PointBase data type to another in the same data type family.
Table 1 : Data Type Families and Data Types
Data Type Family
Data Types
Character String
CHARACTER, VARCHAR, CLOB
Boolean
BOOLEAN
Binary String
BLOB
Date Time
DATE, TIME, TIMESTAMP
Number
SMALLINT, INTEGER, DECIMAL, NUMERIC, REAL, FLOAT, DOUBLE

Table 2 : Mapping Standard Data Types to PointBase SQL Data Types
JDBC Data Types
Java Data Types
PointBase SQL Data Types
BIT
boolean
boolean
TINYINT
byte
smallint
SMALLINT
short
smallint
INTEGER
int
integer
BIGINT
long
numeric/decimal



FLOAT
double
float
REAL
float
real
DOUBLE
double
double



NUMERIC
java.math.BigDecimal
numeric
DECIMAL
java.math.BigDecimal
decimal



CHAR
String
char
VARCHAR
String
varchar
LONGVARCHAR
String
clob



DATE
java.sql.Date
date
TIME
java.sql.Time
time
TIMESTAMP
java.sql.Timestamp
timestamp



BINARY
byte[]
blob
VARBINARY
byte[]
blob
LONGVARBINARY
byte[]
blob



BLOB
Blob
blob
CLOB
Clob
clob



PointBase also supports other non-SQL standard data types. Table 3 describes the mapping of non-SQL standard data types from other database vendors to PointBase data types.

Table 3 : Mapping Non-standard Data Types to PointBase SQL Data Types
Oracle
Data Types
Sybase and Microsoft Data Types
DB2
Data Types
PointBase
Data Types
NUMBER
DECIMAL
TINYINT
SMALLINT
VARCHAR2
VARCHAR
LONGVARCHAR
TEXT
CLOB
LONG
CLOB
CLOB
RAW
BLOB
LONGRAW
BLOB
BINARY
BLOB
VARBINARY
BLOB
IMAGE
BLOB
CHAR for BIT DATA
BLOB
VAR CHAR for BIT DATA
BLOB


 
TOC PREV NEXT