PreviousSQL Engine Reference (v9 SP2 (9.5) revision 1) Next

Pervasive PSQL Supported Data Types

Chapter contents

The following table shows information about the transactional and relational data types supported by Pervasive PSQL. The SRDE converts the relational data types to ODBC default types unless another data type conversion is specified when SQLGetData or SQLBindCol is called. (For a discussion of data type conversions, see the data types appendix in the Microsoft ODBC Programmer's Reference.). Items that are not applicable are designated "n/a."

Table A-1 Pervasive PSQL Data Types and Equivalent ODBC Data Types  
Transactional Type (Size)
Relational Type
ODBC Type (code)1
Type Code
Size (bytes)
Create/Add Parameters
Notes
AUTOINC(2)
SMALLIDENTITY
SQL_SMALLINT(5)
15
2
   
AUTOINC(4)
IDENTITY
SQL_INTEGER(4)
15
4
   
BFLOAT(4)
BFLOAT4
SQL_REAL(7)
9
4
p2
n4
BFLOAT(8)
BFLOAT8
SQL_DOUBLE(8)
9
8
p2
n4
BLOB
LONGVARBINARY
SQL_LONGVARBINARY
(-4)
21
n/a
p2
n2, n3, n6
CLOB
LONGVARCHAR
SQL_LONGVARCHAR
(-1)
21
n/a
p4
n5, n6
CURRENCY
CURRENCY
SQL_DECIMAL(3)
19
8
p2
 
DATE
DATE
SQL_DATE(9)
3
4
p2
 
none
DATETIME
SQL_TIMESTAMP(11)
30
8
p2
n10
DECIMAL
DECIMAL
SQL_DECIMAL(3)
5
1-64
p3
 
FLOAT(4)
REAL
SQL_REAL(7)
2
4
p2
 
FLOAT(8)
DOUBLE
SQL_DOUBLE(8)
2
8
p2
 
GUID
UNIQUEIDENTIFIER
SQL_GUID(-11)
27
16
p2
 
INTEGER(1)
TINYINT
SQL_TINYINT(-6)
1
1
p2
 
INTEGER(2)
SMALLINT
SQL_SMALLINT(5)
1
2
P2
 
INTEGER(4)
INTEGER
SQL_INTEGER(4)
1
4
p2
 
INTEGER(8)
BIGINT
SQL_DECIMAL(3)
1
8
p2
 
NUMERIC
NUMERIC
SQL_NUMERIC(2)
8
1-15
p3
n4
NUMERICSA
NUMERICSA
SQL_NUMERIC(2)
18
1-15
p3
n4
NUMERICSTS
NUMERICSTS
SQL_NUMERIC(2)
17
1-14
p3
n4
STRING
BINARY
SQL_BINARY(-2)
0
1-8,000
p1
n2, n3
STRING
CHAR
SQL_CHAR(1)
0
1-8,000
p1
n1
TIME
TIME
SQL_TIME(10)
4
4
p2
 
TIMESTAMP
TIMESTAMP
SQL_TIMESTAMP(11)
20
8
p2
 
UNSIGNED(1) BINARY
UTINYINT
SQL_TINYINT(-6)
14
1
p2
 
UNSIGNED(2) BINARY
USMALLINT
SQL_SMALLINT(5)
14
2
p2
 
UNSIGNED(4) BINARY
UINTEGER
SQL_INTEGER(4)
14
4
p2
 
UNSIGNED(8) BINARY
UBIGINT
SQL_DECIMAL(3)
14
8
p2
 
WSTRING
not supported in SQL
not supported in SQL
25
n/a
 
n7
WSZSTRING
not supported in SQL
not supported in SQL
26
n/a
 
n7
ZSTRING
VARCHAR
SQL_VARCHAR(12)
11
1-8,000
p1
n5
none
BIT
SQL_BIT(-7)
16
1 bit
 
n6, n8
LOGICAL(1)
BIT
SQL_BIT(-7)
7
1 byte
 
n9
1SQL_FLOAT and SQL_VARBINARY are not supported by Pervasive PSQL
Create/Add Parameters:
p1 - size, not NULL, case
p2 - not NULL
p3 - precision, scale, not NULL
p4 - not NULL, case
Notes:
n1 - padded with spaces
n2 - flag set in FIELD.DDF to tell SQL to use binary
n3 - padded with binary zeros
n4 - cannot be used as variable or in stored procedures
n5 - not padded
n6 - cannot be indexed
n7 - transactional only
n8 - TRUEBITCREATE must be set to "on" (the default)
n9 - TRUEBITCREATE must be set to "off"
n10 - Type code 30 is not a transactional interface type code. It is the identifier for DATETIME within the relational interface metadata

Data Type Ranges

The following table lists the value range for the Pervasive PSQL data types.

Table A-2 Pervasive PSQL Data Type Ranges
Relational Data Type
Valid Value Range
BFLOAT4
-1.70141172e+38  -  +1.70141173e+38
The smallest value by which you can increment or decrement a BLOAT4 is 2.938736e-39
BFLOAT8
-1.70141173e+38 -  +1.70141173e+38
The smallest value by which you can increment or decrement a BLOAT8 is 2.93873588e-39
BIGINT
-9223372036854775808  -  +9223372036854775807
BINARY
range not applicable
BIT
range not applicable
STRING
range not applicable
CURRENCY
-922337203685477.5808  -  +922337203685477.5807
DATE
01-01-0001 - 12-31-9999
DATETIME
January 1, 1753 through December 31, 9999, to an accuracy of one three-hundredth of a second
DECIMAL
depends on the length and number of decimal places
DOUBLE
-1.7976931348623157e+308  -  +1.7976931348623157e+308
The smallest value by which you can increment or decrement a DOUBLE is 2.2250738585072014e-308
FLOAT
-1.7976931348623157E+308  -  +1.7976931348623157E+308
The smallest value by which you can increment or decrement a FLOAT is 2.2250738585072014e-308
IDENTITY
+1  -  +2147483647
INTEGER
-2147483648  -  +2147483647
LOGICAL
range not applicable
LONGVARBINARY
range not applicable
LONGVARCHAR
range not applicable
MONEY
-99999999999999999.99  -  +99999999999999999.99
NUMERIC
Depends on the length and number of decimal places. See Precision and Scale of Decimal Data Types .
NUMERICSA
Depends on the length and number of decimal places. See Precision and Scale of Decimal Data Types .
NUMERICSTS
Depends on the length and number of decimal places. See Precision and Scale of Decimal Data Types .
REAL
-3.4028234E+38  -  +3.4028234e+38
The smallest value by which you can increment or decrement a REL is 1.4E-45
SMALLIDENTITY
+1  -  +32767
SMALLINT
-32768  -  +32767
TIME
00:00:00 - 23:59:59
TIMESTAMP
0001-01-01 00:00:00.0000000  -  9999-12-31 23:59:59.9999999 UTC
TINYINT
-128  -  +127
UBIGINT
0  - 18446744073709551615
UINTEGER
0  -  4294967295
UNIQUEIDENTIFIER
range not applicable
USMALLINT
0  -  65535
UTINYINT
0  -  255
VARCHAR
range not applicable

Operator Precedence

An expression may have multiple operators. Operator precedence determines the sequence in which the operations are performed. Pervasive PSQL uses the following levels of precedence. An operator on a higher level is evaluated before an operator on a lower level. Level one is the highest, level nine the lowest.

  1. + (positive), - (negative), ~ (bitwise NOT)
  2. * (multiply), / (divide), % (modulo)
  3. + (add), (+ concatenate), - (subtract), & (bitwise AND)
  4. =, >, <, >=, <=, <>, != (these comparison operators mean the following, respectively: equals, greater than, less than, greater than equal to, less than equal to, not equal, not equal)
  5. ^ (bitwise Exclusive OR), | (bitwise OR)
  6. NOT
  7. AND
  8. ALL, ANY, BETWEEN, IN, LIKE, OR, SOME
  9. = (assignment)

Two operators in an expression that have the same precedence level are evaluated left to right based on their position within the expression.

For example, in the SET statement in the following procedure, the division operator is evaluated before the multiplication operator. The procedure returns 21.

CREATE PROCEDURE checkvalue(); 
BEGIN 
DECLARE :Counter INTEGER; 
SET :Counter = 12 / 4 * 7; 
PRINT :Counter; 
END 
CALL checkvalue

Parentheses

You may use parentheses to override the defined precedence of the operators in an expression. Everything within the parentheses is evaluated first to yield a single value. The value may then be used by an operator outside of the parentheses.

For example, in the SET statement in the following procedure, the division operator would ordinarily be evaluated before the addition operator. The result would be 12 (that is, 8 + 4). However, the addition is performed first because of the parentheses, so the procedure returns a result of 4.

CREATE PROCEDURE checkvalue1(); 
BEGIN 
DECLARE :Counter INTEGER; 
SET :Counter = 32 / (4 + 4); 
PRINT :Counter; 
END 
CALL checkvalue1

If an expression has nested parentheses, the most deeply nested expression is evaluated first, followed by the next most deeply nested expression, and so forth.

For example, in the following SET statement, the addition is performed first (most deeply nested), then the multiplication, then the subtraction, and finally the division. The result is that the variable evaluates to 5.

SET :Counter = 100 / (40 - (2 * (5 + 5))); 

Data Type Precedence

Data type precedence determines which data type results when two expressions of different data types are combined by an operator. The data type with the lower precedence is converted to the data type with the higher precedence.


Note
Pervasive PSQL returns an error if you perform an operation on incompatible data types. For example, you try to add an INTEGER to a CHAR.

Numeric Data Types

Pervasive PSQL supports the following precedence for the relational numeric data types:

Character Data Types

The precedence for the relational character data types is:

If you concatenate a CHAR or VARCHAR with a LONGVARCHAR, the result is a LONGVARCHAR.

If you concatenate a CHAR with a VARCHAR, the result is the type of the first data type in the concatenation (moving left to right). For example, if c1 is a CHAR and c2 is a VARCHAR, the result of (c1 + c2) is a CHAR; the result of (c2 + c1) is a VARCHAR.

Time and Date Data Types

The precedence for the time and data data types is:

Data Types To Which Precedence Does Not Apply

The BINARY, LONGVARBINARY, and UNIQUEIDENTIFIER data types do not have a precedence because operations to combine them are not allowed.

Precision and Scale of Decimal Data Types

Precision is the number of digits in a number. Scale is the number of digits to the right of the decimal point in a number. The number 909.777 has a precision of 6 and a scale of 3, for instance.

The default maximum precision of numeric and decimal data types is 64.

Precision and scale are fixed for all numeric data types except DECIMAL. An arithmetic operation on two expressions of the same data type results in the same data type, with the precision and scale for that type. If the operation involves expressions with different data types, the precedence rules determine the data type of the result. The result has the precision and scale defined for its data type.

The result is a DECIMAL for the following conditions:

Table A-3 defines how precision and scale are derived when the result of an operation is of data type DECIMAL. "Exp" stands for "expression," "s" stands for "scale," and "p" stands for "precision."

Table A-3 Calculation of Precision and Scale for DECIMAL Operation
Operation
Precision
Scale
Addition (exp1 + exp2)
max(s1, s2) + max(p1 - s1, p2 - s2) +1
max(s1, s2)
Subtraction (exp1 - exp2)
max(s1, s2) + max(p1 - s1, p2 - s2) +1
max(s1, s2)
Multiplication (exp1 * exp2)
p1 + p2 + 1
s1 + s2
Division (exp1 / exp2)
p1 - s1 + s2 + max(6, s1 + p2 +1)
max(6, s1 + p2 +1)
UNION (exp1 UNION exp2)
max(s1, s2) + max(p1 - s1, p2 - s2) +1
max(s1, s2)

Truncation

If your application runs against different SQL DBMS products, you may encounter the following issues pertaining to truncation.

In certain situations, some SQL DBMS products prevent insertion of data because of truncation, while Pervasive PSQL allows the insertion of that same data. Additionally, Pervasive PSQL's reporting of SQL_SUCCESS_WITH_INFO and the information being truncated differs with some SQL DMBS products in some scenarios regarding when the message is reported.

Numeric string data and true numeric data are always truncated by Pervasive PSQL. Some SQL DBMS products round this data when applicable. So if you have a numeric string or true numeric value of 123.457 and you insert it into a 6 bytes string column or precision 2 numeric column, Pervasive PSQL always inserts 123.45. Other DBMS products, by comparison, may insert a value of 123.46.


Chapter contents
Book contents

Prev topic: Data Types
Next topic: Notes on Data Types