Class StringResultWidths

java.lang.Object
dev.frostlake.types.StringResultWidths

public final class StringResultWidths extends Object
How WIDE the string a function returns is declared to be. Snowflake computes a width from the arguments wherever it can, and falls back to the 128MB conversion width where it cannot — it never answers the 16MB a declared column defaults to unless a 16MB column is what went in. Measured function by function on a live account:
   UPPER(v)                v is VARCHAR(5)   VARCHAR(15)          THREE times — upper-casing can lengthen
   LOWER(v)                                  VARCHAR(5)           lower-casing cannot, so it does not
   TRIM / SUBSTR / LEFT                      VARCHAR(5)           the SOURCE width, not the length asked for
   CONCAT(v, w)            w is VARCHAR(9)   VARCHAR(14)          the widths add
   CONCAT_WS(',', v, w)                      VARCHAR(15)          plus the separator, once per gap
   INSERT(v, 1, 1, 'x')                      VARCHAR(11)          twice the base, plus the insert
   MD5 / SHA1 / SHA2                         VARCHAR(32/40/128)   a digest is a fixed width
   HEX_ENCODE(v)                             VARCHAR(40)          8 per character, 2 per BINARY byte
   BASE64_ENCODE(v)                          VARCHAR(28)          4 per 3 bytes, and a character is 4 bytes
   TO_CHAR / CAST(x AS VARCHAR) / CURRENT_*  VARCHAR(134217728)   nothing bounds it, so the maximum
 

Everything saturates at 134217728: CONCAT of eight 16MB columns is exactly that, and of nine still is.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The width a string takes when nothing about its arguments can bound it.
  • Method Summary

    Modifier and Type
    Method
    Description
    static DataType
    forFunction(String funcName, List<DataType> argTypes)
    The width the named function's string result is declared at, or null when the arguments do not determine one and the caller should keep what the registry declares.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • UNBOUNDED

      public static final int UNBOUNDED
      The width a string takes when nothing about its arguments can bound it.
      See Also:
  • Method Details

    • forFunction

      public static DataType forFunction(String funcName, List<DataType> argTypes)
      The width the named function's string result is declared at, or null when the arguments do not determine one and the caller should keep what the registry declares.
      Parameters:
      funcName - the function's name, upper-cased
      argTypes - each argument's declared type, in written order, null where undetermined
      Returns:
      the declared string type, or null