Understanding SQL Data Types

This chapter describes SQL data types, along with data type storage formats, literals, and SQL constants.

Previous Topic

Next Topic

SQL Data Types

The following table lists the SQL data types:

Class

Category

Data Type

Character

Fixed length

c

 

 

char (character)

 

Varying length

text

 

 

varchar (character varying)

 

 

long varchar (clob, character large object, char large object)

Unicode

Fixed length

nchar

 

Varying length

nvarchar

 

 

long nvarchar (clob, nclob, nchar large object, national character large object)

Numeric

Exact numeric

integer (integer4)

 

 

smallint (integer2)

 

 

bigint (integer8)

 

 

tinyint (integer1)

 

 

decimal

 

Approximate numeric

float (float8, double precision)

 

 

float4 (real)

Date/time

Date

date

 

 

ansidate

 

 

ingresdate

 

Time

time (time with time zone, time without time zone, time with local time zone)

 

Timestamp

timestamp (timestamp with time zone, timestamp without time zone, timestamp with local time zone)

 

Interval

interval (interval year to month, interval day to second)

Abstract

(none)

money

 

Logical key

object_key

table_key

Binary

 

byte

 

 

byte varying

 

 

long byte (blob, binary large object)

Previous Topic

Next Topic

Character Data Types

Character data types are strings of characters. Upper and lower case alphabetic characters are accepted literally. There are two fixed-length character data types: char and c, and three variable-length character data types: varchar, long varchar, and text.

The maximum row length is dependent on the default_page_size setting (a DBMS Server configuration parameter), and can be set to a maximum of 32,767 bytes. For further information on page and row size configuration, see the Database Administrator Guide.

The maximum length of a character column is limited by the maximum row width configured, but cannot exceed 32,000. Long varchar columns are an exception: the maximum length of these columns is 2 GB.

Previous Topic

Next Topic

C Data Types

Fixed-length c data types accept only printing characters. Non-printing characters, such as control characters, are converted into blanks.

Blanks are ignored when c strings are compared. For example, this c string:

'the house is around the corner'

is considered equal to:

'thehouseisaroundthecorner'

Note: C is supported for backward compatibility; instead, char is the preferred fixed length character type.

Previous Topic

Next Topic

Char Data Types

Fixed-length char strings can contain any printing or non-printing character, and the null character ('\0'). In uncompressed tables, char strings are padded with blanks to the declared length. (If the column is nullable, char columns require an additional byte of storage.) For example, if ABC is entered into a char(5) column, five bytes are stored, as follows:

'ABC  '

Leading and embedded blanks are significant when comparing char strings. For example, the following char strings are considered different:

'A B C'
'ABC'

When selecting char strings using the underscore (_) wildcard character of the like predicate, include any trailing blanks to be matched. For example, to select the following char string:

'ABC '

the wildcard specification must also contain trailing blanks:

'_____'

Length is not significant when comparing char strings; the shorter string is (logically) padded to the length of the longer. For example, the following char strings are considered equal:

'ABC'
'ABC '

Note: Character is a synonym for char.

Previous Topic

Next Topic

Text Data Types

All ASCII characters except the null character (\0) are allowed within text strings. Null characters are converted to blanks.

Blanks are not ignored when text strings are compared. Unlike varchar, if the strings are unequal in length, blanks are not added to the shorter string. For example, assume that the following text strings are being compared:

'abcd'

and

'abcd '

The string 'abcd  ' is considered greater than the string 'abcd' because it is longer.

Note: Text is supported for backward compatibility; instead, varchar is the preferred varying length character type.

Previous Topic

Next Topic

Varchar Data Types

Varchar strings are variable-length strings, stored as a 2-byte (smallint) length specifier followed by data. In uncompressed tables, varchar columns occupy their declared length. For example, if ABC is entered into a varchar(5) column, the stored result is:

'03ABCxx'

where:

03 is a 2-byte length specifier

ABC is three bytes of data

xx represents two bytes containing unknown (and irrelevant) data.

If the column is nullable, varchar columns require an additional byte of storage.

In compressed tables, varchar columns are stripped of trailing data. For example, if "ABC" is entered into a varchar(5) column in a compressed table, the stored result is:

'03ABC'

The varchar data type can contain any character, including non-printing characters and the ASCII null character ('\0').

Blanks are significant in the varchar data type. For example, the following two varchar strings are not considered equal:

'the store is closed'

and

'thestoreisclosed'

If the strings being compared are unequal in length, the shorter string is padded with trailing blanks until it equals the length of the longer string.

For example, consider the following two strings:

'abcd\001'

where:

'\001' represents one ASCII character (ControlA)

and

'abcd'

If they are compared as varchar data types, then

'abcd' > 'abcd\001'

because the blank character added to 'abcd' to make the strings the same length has a higher value than ControlA ('\040' is greater than '\001').

Previous Topic

Next Topic

Long Varchar Data Types

The long varchar data type has the same characteristics as the varchar data type, but can accommodate strings up to 2 GB in length.

Do not declare a length for long varchar columns. In embedded SQL, data handlers can be created, which are routines to read and write the data for long varchar (and long byte) columns. For more information on data handlers, see Data Handlers for Large Objects and the Embedded SQL Companion Guide.

Previous Topic

Next Topic

Restrictions on Long Varchar Columns

The following restrictions apply to long varchar columns:

Previous Topic

Next Topic

Unicode Data Types

Unicode data types nchar, nvarchar and long nvarchar are used to store Unicode data. They behave similar to char, varchar and long varchar character types respectively, except that each character in Unicode types typically uses 16 bits. Similar to their local character counterparts, nchar types are of fixed length and nvarchar and long nvarchar are of variable length.

Ingres represents Unicode data in UTF-16 encoding form and internally stores them in Normalization Form D (NFD) or Normalization Form C (NFC) depending upon the createdb flag (-n or –i) used for creating the database. Each character of a Unicode value is typically stored in a 2-byte code point (some complex characters require more). The maximum length of a Unicode column is limited by the maximum row width configured, but cannot exceed 16,000 characters for nchar and 15,999 for nvarchar. Long nvarchar columns can have a maximum length of 2 GB.

Unicode data types support the coercion of local character data to Unicode data, and of Unicode data to local character data. Coercion function parameters are valid character data types (for example, char, c, varchar and long varchar) and valid Unicode data types (nchar, nvarchar, and long nvarchar.).

Embedded programs use wchar_t data type to store and process Unicode values.

Note: No matter what size the compilation platform uses for the data type wchar_t, Ingres initializes only the low 16 bits with UTF-16 data. When Ingres reads values from wchar_t variables, the values are coerced to 16 bits and stored in the NFD or NFC canonical form. Applications that make use of any available bits beyond the lower 16 to represent information, for example for UTF-32, will not be able to store that information directly in Ingres. It is the responsibility of the application to convert UTF-32 encoded Unicode to UTF-16 encoded Unicode for use with the Ingres Unicode data types.

For details on Unicode Normalization Forms, go to http://www.unicode.org.

Previous Topic

Next Topic

Numeric Data Types

There are two categories of numeric data types: exact and approximate. Exact data types include integer data types and decimal data types. Approximate data types include floating point data types.

Previous Topic

Next Topic

Integer Data Types

Exact numeric data types includes the following integer data types:

The following table lists the ranges of values for each integer data type:

Integer Data Type

Lowest Possible Value

Highest Possible Value

tinyint (integer1)

-128

+127

smallint (integer2)

-32,768

+32,767

integer (integer4)

-2,147,483,648

+2,147,483,647

bigint (integer8)

-9,223,372,036,854,775,808

+9,223,372,036,854,775,807

Previous Topic

Next Topic

Decimal Data Types

The decimal data type is an exact numeric data type defined in terms of its precision (total number of digits) and scale (number of digits to the right of the decimal point).

The following is an example of precision and scale in decimal values:

The minimum precision for a decimal value is 1 and the maximum precision is 31. The scale of a decimal value cannot exceed its precision. Scale can be 0 (no digits to the right of the decimal point).

Note: The decimal data type is suitable for storing currency data where the required range of values or number of digits to the right of the decimal point exceeds the capacities of the money data type. Note that, for display purposes, a currency sign cannot be specified for decimal values.

Previous Topic

Next Topic

Decimal Data Type Syntax

Specify the decimal data type using the following syntax:

decimal(p,s)

Note: Valid synonyms for the decimal data type are dec and numeric.

Previous Topic

Next Topic

Floating Point Data Types

A floating point value is represented either as whole plus fractional digits (like decimal values) or as a mantissa plus an exponent. The following is an example of the mantissa and exponent parts of floating point values:

There are two floating point data types:

Note: Real is a synonym for float4, while float8 and double precision are synonyms for float.

Floating point numbers are stored in four or eight bytes. Internally, Ingres rounds eight byte numbers to 15 decimal digits. The precision of four byte numbers is processor dependent.

You can specify the binary precision (number of significant bits) for a floating point value using the following optional syntax:

fload(n)

where n is a value from 0 to 53. Storage is allocated according to the precision that is specified, as follows:

Range of Binary Precision

Storage Allocated

0 to 23

4-byte float

24 to 53

8-byte float

Previous Topic

Next Topic

Float Point Limitations

Users must consider the effects of data type conversions when numeric values are combined or compared. This is especially true when dealing with floating point values.

Exact matches on floating point numbers are discouraged, because float and float4 data types are approximate numeric values. Integer and decimal data types, on the other hand, are exact numeric values.

Previous Topic

Next Topic

Date/Time Data Types

Date/time data types include the following:

Previous Topic

Next Topic

Date/Time Input Formats

Date/time data values have the following data type input formats:

Previous Topic

Next Topic

Date Data Type

The declaration format of the date type can be one of the following:

DATE

ANSIDATE

INGRESDATE

Examples:

Date Format

Example

DATE

The keyword DATE used for a column data type is an alias, which can be configured to either ANSIDATE or INGRESDATE by setting the configuration parameter date_type_alias. If this parameter is not set, then the DATE keyword cannot be used in SQL statements.

ANSIDATE

2006-05-16

INGRESDATE

For more information, see Ingresdate Data Types.

Previous Topic

Next Topic

Time Data Types

The TIME data types include the following:

The format is as follows:

TIME [time_precision] [time_zone_spec]

Example:

Time Format

Example

TIME(5) WITH TIME ZONE

12:30:55.12345-05:00

TIME(4) WITHOUT TIME ZONE

12:30:55.1234

TIME(9) WITH LOCAL TIME ZONE

12:30:55.123456789

Note: When a value is entered that exceeds the specified precision, the value is truncated at the specified precision.

Note: The time value in TIME WITH TIME ZONE data type indicates the time at the specified time zone.

Previous Topic

Next Topic

Timestamp Data Types

The TIMESTAMP data type consists of a date and time.

The TIMESTAMP data types include the following:

The format is as follows:

timestamp [(timestamp_precision)] [time_zone_spec]

Example:

Timestamp Format

Example

TIMESTAMP(5) WITH TIME ZONE

2006-12-15 9:30:55.12345-08:00

TIMESTAMP(4) WITHOUT TIME ZONE

2006-12-15 12:30:55.1234

TIMESTAMP(9) WITH LOCAL TIME ZONE

2006-12-15 12:30:55.123456789

Note: Two TIMESTAMP WITH TIME ZONE values are considered identical if they represent the same instant in UTC, regardless of the TIME ZONE offsets stored in the database. For example:

TIMESTAMP '2006-12-15 9:30:55 -8:00'

is the same as

TIMESTAMP '2006-12-15 12:30:55 -5:00'

Note: When a value is entered that exceeds the specified precision, the value is truncated at the specified precision.

Note: The time value in TIMESTAMP WITH TIME ZONE data type indicates the time at the specified time zone.

Previous Topic

Next Topic

Interval Data Types

The INTERVAL data types include the following:

The format is as follows:

interval interval_qualifier

Example:

Interval Format

Example

Explanation

INTERVAL DAY TO SECOND(3)

7 6:54:32.123

An interval of 7 days, 6 hours, 54 minutes, 32 seconds and 123 thousandths of a second

INTERVAL YEAR TO MONTH

123-04

An interval of 123 years, 4 months.

Note: When a value is entered that exceeds the specified precision, the value is truncated at the specified precision.

Previous Topic

Next Topic

Summary of ANSI Date/Type Data Types

The following table summarizes valid input and output formats for ANSI date/time data types:

Data Type

Input and Output Format

Example

ANSIDATE

yyyy-mm-dd

2007-02-28

TIME WITH TIME ZONE

hh:mm:ss.ffff... [+|-]th:tm

12:45:12.23456 -05:00

TIME or TIME WITHOUT TIME ZONE

hh:mm:ss.ffff...

12:45:12.23456

TIME WITH LOCAL TIME ZONE

hh:mm:ss.ffff...

12:45:12.23456

TIMESTAMP WITH TIME ZONE

yyyy-mm-dd hh:mm:ss.ffff... [+|-]th:tm

12:45:12.23456 -05:00

TIMESTAMP or TIMESTAMP WITHOUT TIME ZONE

yyyy-mm-dd hh:mm:ss.ffff... [+|-]th:tm

12:45:12.23456 -05:00

TIMESTAMP WITH LOCAL TIME ZONE

yyyy-mm-dd hh:mm:ss.ffff... [+|-]th:tm

12:45:12.23456 -05:00

INTERVAL YEAR TO MONTH

[+|-]Years-MM

55-4

INTERVAL DAY TO SECOND

[+|-] Days HH:MM:SS.ffff...

-18 12:02:23.12345

where:

Previous Topic

Next Topic

Ingresdate Data Types

The ingresdate data type is an abstract data type. Ingresdate values can contain either absolute dates and times or time intervals. There are six ingresdate data type input formats:

Previous Topic

Next Topic

Absolute Date Input

Ingresdate values are specified as quoted character strings. A date can be entered by itself or together with a time value. If a date is entered without specifying the time, no time is shown when the data displays.

Previous Topic

Next Topic

II_DATE_FORMAT for Ingresdate

The legal formats for absolute ingresdate values are determined by the II_DATE_FORMAT setting, summarized in the following table. If it is not set, the US formats are the default input formats. II_DATE_FORMAT can be set on a session basis. For information on setting II_DATE_FORMAT, see the System Administrator Guide.

The following table lists date input formats:

II_DATE_FORMAT Setting

Valid Input Formats

Output

US (default format)

mm/dd/yy
mm/dd/yyyy
dd-mmm-yyyy
mm-dd-yyyy
yyyy.mm.dd
yyyy_mm_dd
mmddyy
mm-dd
mm/dd

dd-mmm-yyyy

MULTINATIONAL

dd/mm/yy
and all US formats
except mm/dd/yyyy

dd/mm/yy

MULTINATIONAL4

dd/mm/yyyy
and all US formats

dd/mm/yyyy

ISO

yymmdd
ymmdd
yyyymmdd
mmdd
mdd
and all US input formats except mmddyy

yymmdd

ISO4

yymmdd
ymmdd
yyyymmdd
mmdd
mdd
and all US input formats except mmddyy

yyyymmdd

SWEDEN/FINLAND

yyyy-mm-dd

all US input formats
except mm-dd-yyyy

yyyy-mm-dd

GERMAN

dd.mm.yyyy
ddmmyy
dmmyy
dmmyyyy
ddmmyyyy
and all US input formats except yyyy.mm.dd and mmddyy

dd.mm.yyyy

YMD

mm/dd
yyyy-mm-dd
mmdd
yymdd
yymmdd
yyyymdd
yyyymmdd
yyyy-mmm-dd

yyyy-mmm-dd

DMY

dd/mm
dd-mm-yyyy
ddmm
ddmyy
ddmmyy
ddmyyyy
ddmmyyyy
dd-mmm-yyyy

dd-mmm-yyyy

MDY

mm/dd
dd-mm-yyyy
mmdd
mddyy
mmddyy
mddyyyy
mmddyyyy
mmm-dd-yyyy

mmm-dd-yyyy

Year defaults to the current year. In formats that include delimiters (such as forward slashes or dashes), specify the last two digits of the year; the first two digits default to the current century (2000). For example, if this date is entered:

'03/21/03'

using the format mm/dd/yyyy, the DBMS Server assumes that you are referring to March 21, 2003.

In three-character month formats, for example, dd-mmm-yy, specify three-letter abbreviations for the month (for example, mar, apr, may).

To specify the current system date, use the constant, today. For example:

select date('today');

To specify the current system date and time, use the constant, now.

Previous Topic

Next Topic

II_DATE_CENTURY_BOUNDARY

The II_DATE_CENTURY_BOUNDARY variable, which can be set to an integer in the 0< n <=100 range, dictates the implied century for an ingresdate value when only the last two digits of the year are entered.

For example, if II_DATE_CENTURY_BOUNDARY is 50 and the current year is 1999, an input date of 3/17/51 is treated as March 17, 1951, but a date of 03/17/49 is treated as March 17, 2049.

If the II_DATE_CENTURY_BOUNDARY variable is not set or if it is set to 0 or 100, the current century is used. If the user enters the full four digits for the year in a four-digit year field in the application, the year is accepted as entered, regardless of the II_DATE_CENTURY_BOUNDARY setting.

Previous Topic

Next Topic

Absolute Time Input

The legal format for inputting an absolute time into an ingresdate value is:

'hh:mm[:ss] [am|pm] [timezone]'

Input formats for absolute times are assumed to be on a 24-hour clock. If a time with the designation am or pm is entered, the time is converted to a 24-hour internal and displayed representation.

If timezone is omitted, the local time zone designation is assumed. Times are stored as Greenwich Mean Time (GMT) and displayed using the time zone adjustment specified by II_TIMEZONE_NAME.

If an absolute time without a date is entered, the date defaults to the current system date.

Previous Topic

Next Topic

Combined Date and Time Input

Any valid absolute date input format can be paired with a valid absolute time input format to form a valid date and time entry in an ingresdate. The following table shows examples of valid date and time entries, using the US absolute date input formats:

Format

Example

mm/dd/yy hh:mm:ss

11/15/03 10:30:00

dd-mmm-yy hh:mm:ss

15-nov-03 10:30:00

mm/dd/yy hh:mm:ss

11/15/03 10:30:00

dd-mmm-yy hh:mm:ss gmt

15-nov-03 10:30:00 gmt

dd-mmm-yy hh:mm:ss [am|pm]

15-nov-03 10:30:00 am

mm/dd/yy hh:mm

11/15/03 10:30

dd-mmm-yy hh:mm

15-nov-03 10:30

mm/dd/yy hh:mm

11/15/03 10:30

dd-mmm-yy hh:mm

15-nov-03 10:30

Previous Topic

Next Topic

Date Interval

Ingresdate interval values, like absolute date values, are entered as quoted character strings. Date intervals can be specified in terms of years, months, days, or combinations of these. Years and months can be abbreviated to yrs and mos, respectively. For example:

'5 years'
'8 months'
'14 days'
'5 yrs 8 mos 14 days'
'5 years 8 months'
'5 years 14 days'
'8 months 14 days'

The following table lists valid ranges for date intervals:

Date Interval

Range

Years

-9999 to +9999

Months

-119988 to +119988

Days

-3652047 to +3652047

Previous Topic

Next Topic

Time Interval

Time intervals can be specified as hours, minutes, seconds, or combinations of these units. They can be abbreviated to hrs, mins, or secs. For example:

'23 hours'
'38 minutes'
'53 seconds'
'23 hrs 38 mins 53 secs'
'23 hrs 53 seconds'
'28 hrs 38 mins'
'38 mins 53 secs'
'23:38 hours'
'23:38:53 hours'

All values in an interval must be in the range -2,147,483,639 to +2,147,483,639. If a time interval greater than 1 day is entered, the interval is converted to a date and time interval.

For example:

'26 hours'

is converted to:

'1 day 2 hours'

Previous Topic

Next Topic

Date and Time Display

Ingresdate values display as strings of 25 characters with trailing blanks inserted.

To specify the output format of an absolute date and time, set II_DATE_FORMAT. For a list of II_DATE_FORMAT settings and associated formats, see Absolute Date Input. The display format for absolute time is:

hh:mm:ss

The DBMS Server displays 24-hour times for the current time zone, which is determined when Ingres is installed. Dates are stored in Greenwich Mean Time (GMT) and adjusted for your time zone when they are displayed.

If seconds are not entered when entering a time, zeros display in the seconds place.

For a time interval, Ingres displays the most significant portions of the interval that fit in the 25-character string. If necessary, trailing blanks are appended to fill out the string. The format appears as:

yy yrs mm mos dd days hh hrs mm mins ss secs

Significance is a function of the size of any component of the time interval. For instance, if the following time interval is entered:

5 yrs 4 mos 3 days 12 hrs 32 min 14 secs

the entry is displayed as:

5 yrs 4 mos 3 days 12 hrs

Truncating the least significant portion of the time (the minutes and seconds) to fit the result into 25 characters.

Previous Topic

Next Topic

Coercion Between Date/Time Data Types

The rules governing coercion between the various date/time data types are as follows:

  1. Ansidate cannot be converted to any of the time types, nor can the time types be converted to ansidate. Doing so results in error E_AD5066_DATE_COERCION.
  2. When converting from a data type that does not have time zone information to a data type with time zone value (for example, ansidate to a timestamp with time zone, time without time zone to a time with time zone), the time zone is set to the current session time zone.

    Example: In Easter Standard Time (EST) time zone (that is, -05:00), the following statements insert a value of 2007-02-08 16:41:00-05:00 in the database.

    create table tab (col1 timestamp with time zone);

    insert into tab values (TIMESTAMP '2007-02-08 16:41:00');

  3. Ingresdate, time with local time zone, and timestamp with local time zone, store date/time values in UTC. When converting from other data types like ansidate, time with/without time zone, timestamp with/without time zone to these data types, the session time zone displacement is subtracted from the date/time value. On the reverse operation, when converting from ansidate, time with/without time zone, timestamp with/without time zone to ingresdate, time with local time zone and timestamp with local time zone, the session time zone displacement is added to the date/time value in the database to make it in local time zone.

    Example: In EST time zone (with time zone displacement of -05 :00), the following query stores a value of 2007-02-18 15:04:12 in the database:

    create table tab (col1 timestamp with local time zone);

    insert into tab values (TIMESTAMP '2007-02-18 10:04:12');

    If this value was selected in PST time zone (with time zone displacement of -08:00), the session time zone value is added to the value stored in database and the value in local time zone is displayed, that is:

    2007-02-18 07:04:12

  4. When a time value is converted to a timestamp, date, or time/timestamp with local time zone types, the year, month, and day fields are filled with the current year, month, and day value.

    Example: If current date is 08 Feb 2007 then the following statements insert a value of 2007-02-08 17:01:00 in the database:

    create table tab (col1 timestamp);

    insert into tab values (TIME '17:01:00');

  5. When converting from time without time zone to time with local time zone, the following procedure is used:
    1. Current date is added to the time value to make a timestamp.
    2. Time zone displacement is then applied to the time value.
    3. The date part is removed from the result.

      Example: If current date is 08 Feb 2007 and the session time zone is -05 :00 (EST), the following query stores a value of 22:01:00 in the database:

      create table tab (col1 time with local time zone);

      insert into tab values (TIME '17:01:00');

  6. INTERVAL types cannot be converted to any other types except themselves and ingresdates.
  7. When a time/timestamp with time zone is converted to ingresdate, time with local time zone, or timestamp with local time zone, the time value is converted to UTC by applying the time zone information in the value.

    Example: In any time zone, the following query will insert a value of 2007-02-18 03:04:12 in the database:

    create table tab (col1 timestamp with local time zone);

    insert into tab values (TIMESTAMP '2007-02-18 10:04:12-07:00');

Previous Topic

Next Topic

Abstract Data Types

Abstract data types include the following:

Previous Topic

Next Topic

Money Data Types

The money data type is an abstract data type. Money values are stored significant to two decimal places. These values are rounded to their amounts in dollars and cents or other currency units on input and output, and arithmetic operations on the money data type retain two-decimal-place precision.

Money columns can accommodate the following range of values:

$-999,999,999,999.99 to $999,999,999,999.99

A money value can be specified as either:

On output, money values display as strings of 20 characters with a default precision of two decimal places. The display format is:

$[-]dddddddddddd.dd

where:

$ is the default currency symbol
d is a digit from 0 to 9

The following settings affect the display of money data. For details, see the System Administrator Guide:

Variable

Description

II_MONEY_FORMAT

Specifies the character displayed as the currency symbol. The default currency sign is the dollar sign ($). II_MONEY_FORMAT also specifies whether the symbol appears before of after the amount.

II_MONEY_PREC

Specifies the number of digits displayed after the decimal point; valid settings are 0, 1, and 2.

II_DECIMAL

Specifies the character displayed as the decimal point; the default decimal point character is a period (.). II_DECIMAL also affects FLOAT, FLOAT4, and the DECIMAL data types.

Note: If II_DECIMAL is set to comma, be sure that when SQL syntax requires a comma (such as a list of table columns or SQL functions with several parameters), that the comma is followed by a space. For example:

select col1, ifnull(col2, 0), left(col4, 22) from t1:

Previous Topic

Next Topic

Logical Key Data Types

The logical key data type allows the DBMS Server or your application to assign a unique key value to each row in a table. Logical keys are useful when an application requires a table to have a unique key, and the columns of the table do not comprise a unique key.

Previous Topic

Next Topic

Types of Logical Keys

There are two types of logical keys:

Specify the scope of uniqueness for system_maintained logical key columns using the following options:

If two or more system_maintained logical key columns of the same type (object_key or table_key) are created within the same table, the same value is assigned to all columns of the same type in a given row. Different values are assigned to object and table key columns in the same row, as shown in the following diagram:

Table_key values are returned to embedded SQL programs as 8-byte char strings, and object_key values as 16-byte char strings. Values can be assigned to logical keys that are not system_maintained using string literals. For example:

insert into keytable(table_key_column)
values('12345678');

Values assigned to table_keys must be 8-character strings; values assigned to object_keys must be 16-character strings.

Previous Topic

Next Topic

Restrictions on Logical Keys

When working with logical keys, be aware of the following restrictions:

Previous Topic

Next Topic

Binary Data Types

There are three binary data types:

Binary columns can contain data such as graphic images, which cannot easily be stored using character or numeric data types.

Previous Topic

Next Topic

Byte Data Types

The byte data type is a fixed length binary data type. If the length of the data assigned to a byte column is less than the declared length of the column, the value is padded with zeros to the declared length when it is stored in a table. The minimum length of a byte column is 1 byte, and the maximum length is limited by the maximum row width configured but not exceeding 32,000.

Previous Topic

Next Topic

Byte Varying Data Types

The byte varying data type is a variable length data type. The actual length of the binary data is stored with the binary data, and, unlike the byte data type, the data is not padded to its declared length. The minimum length of a byte varying column is 1 byte, and the maximum length is limited by the maximum row width configured but not exceeding 32,000.

Previous Topic

Next Topic

Long Byte Data Types

The long byte data type has the same characteristics as the byte varying data type, but can accommodate binary data up to 2 GB in length. In embedded SQL data handlers can be created, which are routines to read and write the data for long byte columns. For details about data handlers, see Handlers for Large Objects in the chapter "Embedded SQL" and the Embedded SQL Companion Guide.

Previous Topic

Next Topic

Restrictions to Long Byte Data Types

The following restrictions apply to long byte columns:


© 2007 Ingres Corporation. All rights reserved.