Assignment Operations
An assignment operation places a value in a column or variable. Assignment operations occur during the execution of INSERT, UPDATE, CREATE TABLE AS SELECT, and embedded SELECT statements.
The data types of the assigned value and the receiving column or variable must either be the same or comparable.
• If the data types are not the same, comparable data types are converted.
• If the data types are not comparable, convert the assignment value into a type that is the same or comparable with the receiving column or variable.
For information about the type conversion functions, see
Default Type Conversion.
Character String Assignments
All character types are comparable with one another and with integer, decimal, and float types. Any character string can be assigned to any column or variable of character data type. A character string can also be assigned to a column or variable of integer, decimal, or float type, as long as the content of the string is a valid numeric value. The result of the assignment depends on the types of the assignment string and the receiving column or variable.
String Truncation
If an attempt is made to insert a string value into a table column that is too short to contain the value, Vector aborts the statement and issues an error message.
String truncation can occur as a result of the following statements:
• COPY
• CREATE TABLE...SELECT
• INSERT
• UPDATE
The default setting may not be suitable in all cases.
To change error handling behavior for string truncation, use one of these methods:
• Specify the -STRING_TRUNCATION=option flag on the CONNECT statement, specified when a session connects to a database.
• Specify SET STRING_TRUNCATION option for the session.
• Specify the -STRING_TRUNCATION =option flag on the command line for Vector operating system commands that accept SQL option flags.
• Specify the config.string_truncation configuration parameter in config.dat using CBF or the iisetres command.
For valid values, see
SET.
Numeric Assignments
All numeric types are compatible with one another and with character types. Money is compatible with all of the numeric and string data types.
Numeric assignments follow these rules:
• The DBMS Server can truncate leading zeros, or all or part of the fractional part of a number if necessary. If truncation of the non-fractional part of a value (other than leading zeros) is necessary, an overflow error results. These errors are reported only if numeric overflow error handling is set to warn or fail.
• If the receiving column or variable specifies more digits to the right of the decimal point than is present in the assignment value, the assignment value is padded with trailing zeros.
• When a float, float4, decimal, or money value is assigned to an integer column or variable, the fractional part is truncated.
• When a decimal value with a scale greater than two is assigned to a money column or variable, the fractional value is rounded.
• Character data is subject to numeric syntax checks if assigned in a numeric or money context.
Date and Time Assignments
The ANSI date and time data types are compatible between themselves and string columns.
The values of all date and time types can be assigned to string columns. The result is a display version of each value. String values can also be assigned to date and time columns, as long as the string values correspond to the acceptable input format for the particular date and time type.
Note: When a date and time value is retrieved from a database, it is always presented to the user in the appropriate display format in a string variable.
Null Value Assignments
A null can be assigned to a column of any data type if the column was defined as a nullable column. A null can also be assigned to a host language variable if there is an indicator variable associated with the host variable.
To ensure that a null is not assigned to a column, use the IFNULL function.
Last modified date: 12/06/2024