tustvold commented on code in PR #2680:
URL: https://github.com/apache/arrow-datafusion/pull/2680#discussion_r890063548


##########
datafusion/sql/src/utils.rs:
##########
@@ -447,24 +447,21 @@ pub(crate) fn make_decimal_type(
     precision: Option<u64>,
     scale: Option<u64>,
 ) -> Result<DataType> {
-    match (precision, scale) {
-        (None, _) | (_, None) => {
-            return Err(DataFusionError::Internal(format!(
-                "Decimal(precision, scale) must both be specified, got ({:?}, 
{:?})",
-                precision, scale
-            )));
-        }
-        (Some(p), Some(s)) => {
-            // Arrow decimal is i128 meaning 38 maximum decimal digits
-            if (p as usize) > DECIMAL_MAX_PRECISION || s > p {
-                return Err(DataFusionError::Internal(format!(
-                    "For decimal(precision, scale) precision must be less than 
or equal to 38 and scale can't be greater than precision. Got ({}, {})",
-                    p, s
-                )));
-            } else {
-                Ok(DataType::Decimal(p as usize, s as usize))
-            }
-        }
+    // postgres like behavior
+    let (precision, scale) = match (precision, scale) {
+        (Some(p), Some(s)) => (p as usize, s as usize),
+        (Some(p), None) => (p as usize, 0),
+        _ => (DECIMAL_MAX_PRECISION, DECIMAL_DEFAULT_SCALE),

Review Comment:
   ```suggestion
           (None, Some(s)) => Err(DataFusionError::Internal("Cannot specify 
only scale for decimal data type".to_string()))
           (None, None) => (DECIMAL_MAX_PRECISION, DECIMAL_DEFAULT_SCALE),
   ```
   I think this will avoid potential surprises down the line



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to