Teradata Package for Python Function Reference on VantageCloud Lake | 17.20 - to_byte - Teradata Package for Python - Look here for syntax, methods and examples for the functions included in the Teradata Package for Python.

Teradata® Package for Python Function Reference on VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Package for Python
Release Number
17.20
Publication Date
November 2022
Content Type
Programming Reference
Publication ID
B700-4500-112K
ft:locale
en-US
ft:lastEdition
2024-02-21
ft:sourceId
FTML
dita:id
TeradataPython_FxRef_Lake_1720
Product Category
Teradata Vantage
 
 
to_byte

 
Functions
       
to_byte(target_arg)
DESCRIPTION:
    Function converts a numeric data type to the Vantage byte representation
    (byte value) of the input value.
 
PARAMETERS:
    target_arg:
        Required Argument.
        Specifies a ColumnExpression of an numeric column or a numeric literal value.
        If target_arg is NULL, the function returns NULL.
        Format of a ColumnExpression of a column: '<dataframe>.<dataframe_column>.expression'.
        Supported SQL column types: BYTEINT, SMALLINT, INTEGER, and BIGINT
 
        The size of the byte string returned varies according to the data type of the
        target_arg input argument as shown below:
         ==================================================
        | IF target_arg type is | THEN the result type is  |
         ==================================================
        | BYTEINT               | BYTE(1)                  |
        | SMALLINT              | BYTE(2)                  |
        | INTEGER               | BYTE(4)                  |
        | BIGINT                | BYTE(8)                  |
        ===================================================
 
NOTE:
    Function accepts positional arguments only.
 
EXAMPLES:
    # Load the data to run the example.
    >>> load_example_data("dataframe", "bytes_table")
    >>>
 
    # Create a DataFrame on 'bytes_table' table.
    >>> bytes_table = DataFrame("bytes_table")
    >>> bytes_table
           byte_col      varbyte_col             blob_col
    id_col
    2         b'61'  b'616263643132'  b'6162636431323233'
    1         b'62'      b'62717765'  b'3331363136323633'
    0         b'63'      b'627A7863'  b'3330363136323633'
    >>>
 
    # Example converts values in "id_col" to bytes.
    # Import func from sqlalchemy to execute to_byte function.
    >>> from sqlalchemy import func
 
    # Create a sqlalchemy Function object.
    # Note: Function name case does not matter. We can use the function name in
    #       lower case, upper case or mixed case.
    >>> bit_byte_func_ = func.to_byte(bytes_table.id_col.expression)
    >>>
 
    # Pass the Function object as input to DataFrame.assign().
    >>> df = bytes_table.assign(id_col_to_byte_=bit_byte_func_)
    >>> print(df)
           byte_col      varbyte_col             blob_col id_col_to_byte_
    id_col
    2         b'61'  b'616263643132'  b'6162636431323233'            b'2'
    1         b'62'      b'62717765'  b'3331363136323633'            b'1'
    0         b'63'      b'627A7863'  b'3330363136323633'            b'0'
    >>>