The conversion unary operatorsstring,int,char,float,oidandidentallows us to make the following conversions:
Operator From To Returned Atom
string any type string the string representation of the operand
int int int theintoperand
char int the operand casted to anint float int the operand casted to anint string int the operand converted to anint
char char char thecharoperand
int char the operand casted to achar float textttchar the operand casted to achar string char the operand converted to achar
float float float thefloatoperand
char float the operand casted to afloat int float the operand casted to afloat string float the operand converted to afloat
oid oid oid theoidoperand
string oid thestringoperand converted to anoid
ident ident ident theidentoperand
string ident thestringoperand converted to anident
These operators are used to perform an explicit conversion such as convert the string"123" to the integer 123, or to perform an explicit cast for numbers such as casting the integer10 to the float10.0. These operators evaluate first their operand before performing the conversion. If the operand type is valid, no error is raised even if its format is not valid, for instance: int "alpha"returns0, whileoid "aoaoai"returnsNULL. Note that because of the precedence of these operators, parenthesis are necessary to make a conversion of a non-primary operand. For instance, string 1+2is not valid: you should usestring (1+2).
string operator
Thestringoperator evaluates its operand and returns its string representation.
General Information
Operator string
Syntax stringexpr
Type unary
Operand Type any type Result Type string
Function returns the string representation of any atom
Expression Examples
string 123.3 "1203.300000"
string ’a’ "a"
string first(select Person) "71211.13.1486847:oid"
string &alpha "::alpha"
string list(1, 2, 3+2) "list(1, 2, 5)"
string (list("hello", 30) + list(10)) "list("hello", 30, 10)"
string (1+3) "4"
string 1+3 raises an error
int operator
Theintoperator evaluates its operand and converts or casts it to an integer.
If the operand is the string, it converts it using theatoiC function. If the string is not a valid integer, it returns a0.
If the operand is a char or float, it casts it to an integer.
If the operand is an integer, it returns it.
General Information
Operator int
Syntax intexpr
Type unary
Operand Type int,char,floatorstring Result Type int
Function returns the integer conversion or cast of the operand
Expression Examples
int 123.3 123
int 12 12
int ’a’ 97
int "123" 123
int ("123" + "12") 12312
int alpha the value of alpha converted or
casted to an integer
int list(1, 2, 3) raises an error
char operator
Thecharoperator evaluates its operand and converts or casts it to achar.
If the operand is the string of length one, it returns the character of this string. If the string has several characters, it returns a’\000.
If the operand is a integer or float, it casts it to a character.
If the operand is a character integer, it returns it.
General Information
Operator char
Syntax charexpr
Type unary
Operand Type int,char,floatorstring Result Type char
Function returns the character conversion or cast of the operand
Expression Examples
char 123.3 {
char ’a’ ’a’
char alpha the value of alpha converted or
casted to a character
char "a" ’a’
char "hello" ’^@’
char list(1, 2, 3) raises an error
float operator
Thefloatoperator evaluates its operand and converts or casts it to a float.
If the operand is the string, it converts it using theatofC function. If the string is not a valid float, it returns a0.0.
If the operand is a integer or float, it casts it to a float.
If the operand is a float, it returns it.
General Information
Operator float
Syntax floatexpr
Type unary
Operand Type int,char,floatorstring Result Type float
Function returns the float conversion or cast of the operand
Expression Examples
float 123.0 123.0
float 123.3 123.3
float ’a’ 97.000
float "123.0000000" 123.0
float ("123." + "12") 123.12
float "hello" 0.0
float alpha the value of alpha converted or
casted to a float
float list(1, 2, 3) raises an error
oid operator
Theoidoperator evaluates its string operand and returns the corresponding oid. If the string does not denote a valid oid, theNULLoid is returned.
If the operand is an oid, it returns it.
General Information
Operator oid
Syntax oidexpr
Type unary
Operand Type oidorstring Result Type oid
Function returns the oid denoted by the string operand
Expression Examples
oid "234.34.33:oid" 234.34.33:oid
oid 234.34.33:oid 234.34.33:oid
oid first(select Person) returns the first person oid
oid ’a’ raises an error
ident operator
Theidentoperator evaluates its string operand and returns the corresponding identifier. If the operand is an identifier, it returns it.
General Information
Operator ident
Syntax identexpr
Type unary
Operand Type identorstring Result Type string
Function returns the identifier denoted by the string operand
Expression Examples
ident "alpha" alpha
ident "alpha#1x" alpha#1x
ident "alpha" := 123 123,alphahas been assigned to123 valof &(ident "alpha") 123
ident ’a’ raises an error