- When mixing different data types while combining two result sets with
UNION. - When passing to functions and operators, operands of different types than their input operand types.
- When assigning values of different types to table row cells.
-
When combining queries (
UNION[ALL]), Regatta converts the data types of both queries to the “larger” data type of them. E.g: DuringUNIONon two queries, if the first returnsDATEand the other returnsTIMESTAMP, Regatta converts theDATEintoTIMESTAMP. - When converting strings to other data types, the conversion fails if the string is not a valid representation of the value of the target type. For example, conversion of ‘3’ to Integer would succeed but conversion of ‘ttt’ or ‘3.1’ to integer would fail.
-
When converting from
FLOAT4/8orDECIMALto integers, the value is rounded to the closest integer. -
During
INSERTandUPDATEoperations, Regatta converts the value to the datatype of the affected column. If the value is too large for the target data type, the operation fails. -
Conversion from
TIMESTAMPtoDATEorTIMEextracts the relevant part of theTIMESTAMPinto the target element. E.g:SELECT '2023-12-12 23:00:05'::timereturns23:00:05. -
When converting integral types to
BOOLEAN,0is converted toFALSEand any other value is converted toTRUE. -
Any conversion (explicit or implicit) to a numeric type (integers, floating point and decimals) would fail if the value cannot fit within the range of the target type.
For example,
SELECT 1234567::SMALLINTwill fail since the value is out of theSMALLINTrange. -
Explicit conversion to Character types trims the converted string to fit the size of the target type, however, implicit conversion would not trim the text and would result in an error.
For example:
CAST(150 as CHAR(2))returns15but assigning150to aCHAR(2)column without explicit casting would fail. -
CHARtypes are implicitly converted toVARCHAR(and the trailing spaces are trimmed) when they are used as inputs to any function/operation. For example: Comparison ofVARCHAR(10)containing the value‘Regatta’andCHAR(10)containing the value‘Regatta ’results inTRUE. Note: If theVARCHARcontains trailing spaces as part of its string, the comparison will returnFALSE. For example:CHAR(10)with the text'Regatta'is not equal toVARCHAR(10)with the text'Regatta '.