Reference Guide > TDV Support for SQL Operators > Arithmetic Operators > Divide
 
Divide
The divide operator ( / ) divides the first operand by the second and returns the quotient.
Note: A configuration parameter is available to control whether this operator allows precision/scale to exceed 38. See Decimal Digit Limitation on Functions, for details.
DECIMAL and NUMERIC Data Types
When the divide operator is applied to operands that include DECIMAL or NUMERIC data types, the output data type, precision and scale might depend on the data type, precision and scale of the operands, as shown below.
Syntax
operand1 / operand2
Remarks
The order of the inputs (operands) has no effect on the output data type.
The outputs for dividing DECIMAL and NUMERIC data types are shown in the table.
operand1
operand2
Output
DECIMAL(p1,s1)
DECIMAL(p2,s2)
DECIMAL(p1+p2+s2,s1+p2)
DECIMAL(p,s)
NUMERIC
DECIMAL(p,s)
NUMERIC
NUMERIC
NUMERIC
If the input is DECIMAL or NUMERIC with any number data types other than DECIMAL or NUMERIC, the output data type should be DECIMAL or NUMERIC, respectively, with the same precision and scale as the DECIMAL or NUMERIC input.
Example
DECIMAL(12,3) / DECIMAL(45,2)
 
This division operation returns DECIMAL(59,48).
Note: If an expression that is computed, has an undefined result (for example, 0/0), the classic query engine throws an exception. For a similar scenario, the MPP Engine returns the value “NaN”. The results may vary if the query is pushed down to a datasource.
INTERVAL Type
INTERVAL can be divided by numbers. The output is an INTERVAL.
Syntax
INTERVAL / NUMERIC
Example
INTERVAL '90' HOUR / 10 = INTERVAL '0 09:00:00' DAY TO SECOND
INTERVAL '1' YEAR / .1 = INTERVAL '10-00' YEAR TO MONTH