Search code examples
snowflake-cloud-data-platformaggregate-functions

How min(numeric string) works in snowflake


select min(val) from (select '10026096' as val union select '1002793' as val);

The above sql query return the following output:

MIN(VAL)
10026096

Please help me understand why snowflake is giving numerically bigger number as output amongst the two. How does it process numeric string in min function.


Solution

  • Keeping data using correct data type is the key and INT != STRING.

    1 0 0 2 6 0 9 6
    = = = = <
    1 0 0 2 7 9 3
    

    Therefore string 10026096 is lower than 1002793.


    SELECT '10026096' < '1002793'
         , 10026096 < 1002793;
    

    Output:

    '10026096' < '1002793' 10026096 < 1002793
    TRUE FALSE