github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/sem/tree/testdata/eval/func (about)

     1  # Func expressions.
     2  
     3  eval
     4  length('hel'||'lo')
     5  ----
     6  5
     7  
     8  eval
     9  lower('HELLO')
    10  ----
    11  'hello'
    12  
    13  # lint: uppercase function OK
    14  eval
    15  UPPER('hello')
    16  ----
    17  'HELLO'
    18  
    19  # Scale < -Exponent.
    20  eval
    21  crdb_internal.round_decimal_values(1.23:::decimal, 1)
    22  ----
    23  1.2
    24  
    25  # Scale = -Exponent.
    26  eval
    27  crdb_internal.round_decimal_values(1.23:::decimal, 2)
    28  ----
    29  1.23
    30  
    31  # Scale > -Exponent.
    32  eval
    33  crdb_internal.round_decimal_values(1.23:::decimal, 3)
    34  ----
    35  1.23
    36  
    37  # Scale=0 with whole number.
    38  eval
    39  crdb_internal.round_decimal_values(123:::decimal, 0)
    40  ----
    41  123
    42  
    43  # Scale=0 with fractional number.
    44  eval
    45  crdb_internal.round_decimal_values(0.123:::decimal, 0)
    46  ----
    47  0
    48  
    49  # Special-value cases.
    50  eval
    51  crdb_internal.round_decimal_values('NaN'::decimal, 0)
    52  ----
    53  NaN
    54  
    55  eval
    56  crdb_internal.round_decimal_values('-inf'::decimal, 0)
    57  ----
    58  -Infinity
    59  
    60  eval
    61  crdb_internal.round_decimal_values('inf'::decimal, 0)
    62  ----
    63  Infinity
    64  
    65  # NULL value.
    66  eval
    67  crdb_internal.round_decimal_values(null, 0)
    68  ----
    69  NULL
    70  
    71  # NULL decimal value.
    72  eval
    73  crdb_internal.round_decimal_values(null::decimal, 0)
    74  ----
    75  NULL
    76  
    77  # Round 10th fractional digit.
    78  eval
    79  crdb_internal.round_decimal_values(1000000000000000.0000000005::decimal, 9)
    80  ----
    81  1000000000000000.000000001
    82  
    83  # Truncate extra zeros.
    84  eval
    85  crdb_internal.round_decimal_values(1000000000000000.0000000000::decimal, 3)
    86  ----
    87  1000000000000000.000
    88  
    89  # Round with 1 digit coefficient and large negative exponent.
    90  eval
    91  crdb_internal.round_decimal_values(0.0000000005::decimal, 9)
    92  ----
    93  1E-9
    94  
    95  # Decimal in array.
    96  eval
    97  crdb_internal.round_decimal_values(ARRAY[1.25::decimal], 1)
    98  ----
    99  ARRAY[1.3]
   100  
   101  # Multiple array values need to be rounded + NULL values.
   102  eval
   103  crdb_internal.round_decimal_values(ARRAY[NULL, 1.25::decimal, NULL, 1.23::decimal], 1)
   104  ----
   105  ARRAY[NULL,1.3,NULL,1.2]
   106  
   107  # None of the array values need to be rounded.
   108  eval
   109  crdb_internal.round_decimal_values(ARRAY[1.2::decimal, 5::decimal, NULL], 1)
   110  ----
   111  ARRAY[1.2,5,NULL]