INFORMIX
Informix Guide to SQL: Syntax
Chapter 1: SQL Statements
Home Contents Index Master Index New Book

SQL Statements

Data Type

The Data Type segment specifies the data type of a column or value. Use the Data Type segment whenever you see a reference to a data type in a syntax diagram.

Syntax

Usage

The following sections summarize each of the categories of data types that the Universal Server supports. For more information, see the discussion of all data types in the Informix Guide to SQL: Syntax.

Built-In Data Type

Built-in data types are data types that are fundamental to the database server. These data types are built into the database server in the sense that the knowledge for how to interpret and transfer these data types is part of the database server software.

Universal Server supports the following categories of built-in data types:

The following sections describe each of the data-type categories in more detail.

In addition, Universal Server supports the BOOLEAN data type. For more information on the BOOLEAN data type, see Chapter 2 of the Informix Guide to SQL: Syntax and Chapter 9 of the Informix Guide to SQL: Tutorial.

Character Data Types

Element Purpose Restrictions Syntax

max

Maximum size of a CHARACTER VARYING or VARCHAR or NVARCHAR column in bytes

You must specify an integer value between 1 and 255 bytes inclusive. If you place an index on the column, the largest value you can specify for max is 254 bytes.

Literal Number, p. 1-1001

size

Number of bytes in the CHAR or NCHAR column

You must specify an integer value between 1 and 32,767 bytes inclusive.

Literal Number, p. 1-1001

reserve

Amount of space in bytes reserved for a CHARACTER VARYING or VARCHAR or NVARCHAR column even if the actual number of bytes stored in the column is less than reserve

You must specify an integer value between 0 and 255 bytes. However, the value you specify for reserve must be less than the value you specify for max.

Literal Number, p. 1-1001

The following table summarizes the character data types that Universal Server supports.

Data Type Purpose

CHAR

Stores single-byte or multibyte text strings of up to 32,767 bytes of text data and supports code-set collation of text data.

CHARACTER

Is an ANSI-compliant synonym for CHAR.

CHARACTER VARYING

Is a synonym for VARCHAR that complies with ANSI standards.

LVARCHAR

NCHAR

Stores variable length strings that are potentially longer than 255 bytes.

Store single-byte or multibyte text strings of up to 32,767 bytes of text data and supports localized collation of the text data

NVARCHAR

Stores single-byte or multibyte text strings of varying length and up to 255 bytes of text data; it supports localized collation of the text data.

VARCHAR

Stores single-byte or multibyte text strings of varying length and up to 255 bytes of text data; it supports code-set collation of the text data.

The TEXT and CLOB data types also support character data. For more information, see "Large-Object Data Types".

For more information on individual data types, see the description of the above data types in Chapter 2 of the Informix Guide to SQL: Syntax.

Fixed- and Varying- Length Data Types
Universal Server supports storage of fixed-length and varying-length character data. A fixed-length column requires the defined number of bytes regardless of the actual size of the character data. The CHAR data type is a fixed-length character data types. For example, a CHAR(25) column requires 25 bytes of storage for all its column values so the string "This is a text string" uses 25 bytes of storage. Use the ANSI-compliant CHARACTER VARYING data type to specify varying length character data.

A varying-length column requires only the number of bytes that its data uses. The VARCHAR and LVARCHAR data types are varying-length character data types. For example, a VARCHAR(25) column reserves up to 25 bytes of storage for the column value, but the string "This is a text string" uses only 21 bytes of the reserved 25 bytes.

The VARCHAR data type can store up to 255 bytes of varying data while the LVARCHAR data type can store up to 32 kilobytes of text data.

NCHAR and NVARCHAR Data Types
The character data types CHAR, LVARCHAR, and VARCHAR support code-set collation of the text data. That is, the database server collates text data in columns of these types by the order that their characters are defined in the code set.

To accommodate locale-specific order of characters, use the NCHAR and NVARCHAR data types. The NCHAR data type is the fixed-length character data type the supports localized collation. The NVARCHAR data type is the varying-length character data type that can store up to 255 bytes of text data and supports localized collation.

For more information, see the Guide to GLS Functionality.

Numeric Data Types

Numeric data types allow the database server to store numbers such as integers and real numbers in a column. These data types fall into the following two categories:

Exact Numeric Data Types

Element Purpose Restrictions Syntax

precision

Total number of significant digits in a decimal or money data type

You must specify an integer between 1 and 32, inclusive.

Literal Number, p. 1-1001

scale

Number of digits to the right of the decimal point

You must specify an integer between 1 and precision.

Literal Number, p. 1-1001

start

Starting number for values in a SERIAL or SERIAL8 column

For SERIAL columns you must specify a number greater than 0 and less than 2,147,483,647.

For SERIAL8 columns you must specify a number greater than 0 and less than 9,223,372,036,854,775,807.

Literal Number, p. 1-1001

An exact numeric data type stores a numeric value with a specified precision and scale. The precision of a number is the number of digits that the data type stores. The scale is the number of digits to the right of the decimal separator.

The following table summarizes the exact numeric data types that Universal Server supports.

(1 of 2)

Data Type Purpose

DEC(p,s)

Is a synonym for DECIMAL(p,s).

DECIMAL(p,s)

Stores fixed-point decimal (real) values in the range. The p parameter indicates the precision of the decimal value and the s parameter indicates the scale. If no precision is specified, the system default of 16 is used. If no scale is specified, the system default of 0 is used.

INT

Is a synonym for INTEGER.

INTEGER

Stores a 4-byte integer value. These values can be in the range
-((2**31)-1) to (2**31)-1 (the values -2,147,483,647 to 2,147,483,647).

INT8

Stores an 8-byte integer value. These values can be in the range -((2**63)-1) to (2**63)-1 (the values -9,223,372,036,854,775,807 to 9,223,372,036,854,775,807).

MONEY(p,s)

Stores fixed-point currency values. Has the same internal data type as a fixed-point DECIMAL value.

NUMERIC(p,s)

Is an ANSI-compliant synonym for DECIMAL(p,s).

SERIAL

Stores a 4-byte integer value that the database server generates. These values can be in the range -((2**31)-1) to (2**31)-1 (the values -2,147,483,647 to 2,147,483,647).

SERIAL8

Stores an 8-byte integer value that the database server generates. These values can be in the range -((2**63)-1) to (2**63)-1 (the values -9,223,372,036,854,775,807 to 9,223,372,036,854,775,807).

SMALLINT

Stores a 2-byte integer value. These values can be in the range
-((2**15)-1) to (2**15)-1 (-32,767 to 32,767).

For more information, see the entries for these data types in Chapter 2 of the Informix Guide to SQL: Syntax.

Approximate Numeric Data Types

Element Purpose Restrictions Syntax

float precision

The float precision is ignored.

You must specify a positive integer.

Literal Number, p. 1-1001

An approximate numeric data type represents numeric values approximately. Use them for very large and very small numbers that can tolerate some degree of rounding during arithmetic operations.

The following table summarizes the approximate numeric data types that Universal Server supports.

Data Type Purpose

DOUBLE PRECISION

Is an ANSI-compliant synonym for FLOAT.

FLOAT

Stores double-precision floating-point numbers with up to 16 significant digits.

REAL

Is an ANSI-compliant synonym for SMALLFLOAT.

SMALLFLOAT

Stores single-precision floating-point numbers with approximately 8 significant digits.

For more information, see the entries for these data types in Chapter 2 of the Informix Guide to SQL: Syntax.

Large-Object Data Types

Element Purpose Restrictions Syntax

blobspace

Name of an existing blobspace

The blobspace must exist.

Identifier, p. 1-966

family name

Quoted string constant that specifies a family name or variable name in the optical family

The family name or variable name must exist.

Quoted String, p. 1-1014

For additional information about optical families, see the INFORMIX-OnLine/Optical User Manual.

Large-object data types allow the database server to store extremely large column values such as images and documents independently of the column. These data types fall into the following two categories:

Simple-Large-Object Data Types
A simple-large-object data type stores text or binary data in blobspaces or in tables. (For information on how to create blobspaces, see the INFORMIX-Universal Server Administrator's Guide.) The database server can access a simple-large-object value in one piece. These data types are not recoverable.

The following table summarizes the simple-large-object data types that Universal Server supports.

Data Type Purpose

TEXT

Stores text data of up to 2**31 bytes.

BYTE

Stores text data of up to 2**31 bytes.

For more information, see the entries for these data types in Chapter 2 of the Informix Guide to SQL: Syntax.

Smart-Large-Object Data Types
A smart-large-object data type stores text or binary data in sbspaces. (For information about how to create sbspaces, see the INFORMIX-Universal Server Administrator's Guide.) The database server can provide random access to a smart-large-object value. That is, it can access any portion of the smart-large-object value. These data types are recoverable.

The following table summarizes the smart-large-object data types that Universal Server supports.

Data Type Purpose

CLOB

Stores text data of up to 4 terabytes (4*2 bytes).

BLOB

Stores binary data of up to 4 terabytes (4*2 bytes).

For more information, see the entries for these data types in Chapter 2 of Informix Guide to SQL: Syntax. For information about the SQL functions you use to import, export, and copy smart large objects, see "Smart-Large-Object Functions" in this manual and Chapter 9 of the Informix Guide to SQL: Tutorial.

Time Data Types

The time data types allow the database server to store increments of time. The following table summarizes the time data types that Universal Server supports.

Data Type Purpose

DATE

Stores a date value (mm/dd/yy) as a Julian date.

DATETIME

Stores a date and time value (mm/dd/yy hh:mm:ss.fff) in an internal format.

INTERVAL

Stores a unit of time such as seconds, hours/minutes, or year/month/day.

For more information, see the entries for these data types in Chapter 2 of the Informix Guide to SQL: Syntax.

User-Defined Data Type

Element Purpose Restrictions Syntax

opaque data type

The name of the opaque data type

The name must be different from all other data types in the database.

Identifier, p. 1-966

distinct data type

The name of a distinct data type that has the same structure as an existing data type

The name must be different from all other data types in the database.

Identifier, p. 1-966

owner

The user name of the owner of the data type

If you are using an ANSI compliant database, you must enter the owner.type name to use a user-defined data type that you do not own. If you put quotation marks around the name you enter in owner, the named is stored exactly as typed. If you do not put quotation marks around the name that you enter in owner, the name is stored as uppercase letters.

The user name must conform to the conventions of your operating system.

A user-defined data type is a data type that a user defines for the database server. Universal Server supports the following categories of user-defined data types:

The following sections describe the user-defined data types in greater detail.

Opaque Data Types

An opaque data type is a user-defined data type that can be used in the same way as a built-in data type. To create an opaque type, you must use the CREATE OPAQUE TYPE statement. Because an opaque type is encapsulated, you create functions to access the individual components of an opaque type. The internal storage details of the type are hidden, or opaque.

For more information, see the CREATE OPAQUE TYPE statement. For complete information about how to create an opaque type and its support functions, see the Extending INFORMIX-Universal Server: Data Types manual.

Distinct Data Types

A distinct data type is user-defined data type that is based on an existing built-in type, opaque type, named row type, or distinct type. To create a distinct type, you must use the CREATE DISTINCT TYPE statement. For more information, see the CREATE DISTINCT TYPE statement.

Complex Data Type

Element Purpose Restrictions Syntax

named row type name

The name of the named row type

The name must be different from all other data types in the database.

Identifier, p. 1-966

Data type, p. 1-859

owner

The user name of the owner of the data type

If you are using an ANSI-compliant database, you must enter the owner.type name to use a named row type that you do not own. If you put quotation marks around the name you enter in owner, the named is stored exactly as typed. If you do not put quotation marks around the name that you enter in owner, the name is stored as uppercase letters.

The user name must conform to the conventions of your operating system.

Complex data types are data types that you create from built-in types, opaque types, distinct types, or other complex types. When you create a complex type, you define the components of the complex type. However, unlike an opaque type, a complex type is not encapsulated. You can use SQL to access the individual components of a complex data type.

Universal Server supports the following categories of complex data types:

For a full discussion of complex data types, see Chapter 10 of the Informix Guide to SQL: Tutorial.

Named Row Types

You can assign a named row type to a table or a column. To use a named row type to create a typed table or define a column, the named row type must already exist. To create a named row type, you use the CREATE ROW TYPE statement. For a description of the CREATE ROW TYPE statement, see page 1-197.

For a complete description of named row types, see Chapter 10 of the Informix Guide to SQL: Tutorial and Chapter 2 of the Informix Guide to SQL: Syntax.

Unnamed Row Types

An unnamed row type is a group of fields that you create with the ROW constructor. You can use an unnamed row type to define a column. The syntax that you use to define a column as an unnamed row type is shown in the following diagram.

An unnamed row type is identified by its structure. For additional information about unnamed row types and how to create them, see Chapter 10 of the Informix Guide to SQL: Tutorial and Chapter 2 in the Informix Guide to SQL: Syntax.

For the syntax you use to specify row values for an unnamed row type, see the "Expression" segment on page 1-880.

Field Definition
The syntax you use to define the fields of an unnamed row type is shown in the following diagram.

Element Purpose Restrictions Syntax

field name

The name of a field in the row.

The name must be unique within the row type.

Identifier, p. 1-966

data type

The data type of the field.

The field can be any data type except TEXT, BYTE, SERIAL, or SERIAL8.

Data Type, p. 1-859

Collection Data Types

The syntax you use to define a column as a collection type is shown in the following diagram.

Element Purpose Restrictions Syntax

element type

Specifies the data type of the elements of the collection.

The element type can be any data type except TEXT, BYTE, SERIAL, or SERIAL8.

Data Type, p. 1-859

A collection type contains elements that can be of a built-in type, an opaque type, a distinct type, or a row type. A collection type can also contain another collection type within it. You can use a collection type to define a column. The element type of a collection specifies the type of data that the collection can contain. For example, if the element type of a collection type is INTEGER, every element in the collection must be of type INTEGER. If the element type of a collection type is a row type, every element in the collection must be of the row type.

To create a collection data type, you must specify the following:

Privileges on a collection type are those of the column. You cannot specify privileges on specific elements of a collection.

For the syntax you use to specify collection values for a collection data type, see the "Literal DATETIME" segment on page 1-995.

SET Collection Types
A SET is an unordered collection of elements in which each element is unique. You define a column as a SET collection type when you want to store collections whose elements contain no duplicate values and no specific order associated with them.

MULTISET Collection Types
A MULTISET is an unordered collection of elements in which elements can have duplicate values. You define a column as a MULTISET collection type when you want to store collections whose elements might not be unique and have no specific order associated with them.

LIST Collection Types
A LIST is an ordered collection of elements that allows duplicate elements. A LIST differs from a MULTISET in that each element in a LIST collection has an ordinal position in the collection. You define a column as a LIST collection type when you want to store collections whose elements might not be unique but have a specific order associated with them.

References

See the CREATE TABLE statement in this manual.

In the Informix Guide to SQL: Tutorial, see the discussion of complex data types in Chapter 10.

In the Informix Guide to SQL: Syntax, see the discussions of individual data types in Chapter 2.

In the Guide to GLS Functionality, see the discussion of the NCHAR and NVARCHAR data types and the GLS aspects of other character data types.

DATETIME Field Qualifier

A DATETIME field qualifier specifies the largest and smallest unit of time in a DATETIME column or value. Use the DATETIME Field Qualifier segment whenever you see a reference to a DATETIME field qualifier in a syntax diagram.

Syntax

Element Purpose Restrictions Syntax

digit

A single integer that specifies the precision of a decimal fraction of a second. The default precision is 3 digits (a thousandth of a second).

You must specify an integer between 1 and 5, inclusive.

Literal Number, p. 1-1001

Usage

Specify the largest unit for the first DATETIME value; after the word TO, specify the smallest unit for the value. The keywords imply that the following values are used in the DATETIME object.

Unit of Time Meaning

YEAR

Specifies a year, numbered from A.D. 1 to 9999

MONTH

Specifies a month, numbered from 1 to 12

DAY

Specifies a day, numbered from 1 to 31, as appropriate to the month in question

HOUR

Specifies an hour, numbered from 0 (midnight) to 23

MINUTE

Specifies a minute, numbered from 0 to 59

SECOND

Specifies a second, numbered from 0 to 59

FRACTION

Specifies a fraction of a second, with up to five decimal places. The default scale is three digits (thousandth of a second).

The following examples show DATETIME qualifiers:

References

In the Informix Guide to SQL: Syntax, see the DATETIME data type in Chapter 2 for an explanation of the DATETIME field qualifier.




Informix Guide to SQL: Syntax, version 9.1
Copyright © 1998, Informix Software, Inc. All rights reserved.