Teradata Package for Python Function Reference - current_timestamp - 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

Product
Teradata Package for Python
Release Number
17.00
Published
November 2021
Language
English (United States)
Last Update
2021-11-19
lifecycle
previous
Product Category
Teradata Vantage
 
 
current_timestamp

 
Functions
       
current_timestamp(fractional_precision)
DESCRIPTION:
    Function returns the current timestamp when the request started.
    If function is invoked more than once during the request, the same timestamp is returned.
    The timestamp returned does not change during the duration of the request.
 
    The value returned depends on the setting of the DBS Control flag TimeDateWZControl as follows:
        * If the TimeDateWZControl flag is enabled, function returns a timestamp constructed from
          the session time and session time zone.
        * If the TimeDateWZControl flag is disabled, function returns a timestamp constructed from
          the time value local to the Vantage server and the session time zone.
 
PARAMETERS:
    fractional_precision:
        Optional Argument.
        Specifies a precision range for the returned value. The valid range
        is 0 through 6. The default is 0.
 
NOTE:
    Function accepts positional arguments only.
 
EXAMPLES:
    # Load the data to run the example.
    >>> load_example_data("dataframe", "admissions_train")
    >>>
 
    # Create a DataFrame on 'admissions_train' table.
    >>> admissions_train = DataFrame("admissions_train")
    >>> admissions_train
       masters   gpa     stats programming  admitted
    id
    22     yes  3.46    Novice    Beginner         0
    36      no  3.00  Advanced      Novice         0
    15     yes  4.00  Advanced    Advanced         1
    38     yes  2.65  Advanced    Beginner         1
    5       no  3.44    Novice      Novice         0
    17      no  3.83  Advanced    Advanced         1
    34     yes  3.85  Advanced    Beginner         0
    13      no  4.00  Advanced      Novice         1
    26     yes  3.57  Advanced    Advanced         1
    19     yes  1.98  Advanced    Advanced         0
    >>>
 
    # Import func from sqlalchemy to execute current_timestamp() function.
    >>> from sqlalchemy import func
 
    # Create a sqlalchemy Function object.
    >>> current_timestamp_ = func.current_timestamp()
    >>>
 
    # Pass the Function object as input to DataFrame.assign().
    >>> df = admissions_train.assign(current_timestamp_col=current_timestamp_)
    >>> print(df)
       masters   gpa     stats programming  admitted current_timestamp_col
    id
    13      no  4.00  Advanced      Novice         1   02:32:17+00:00
    36      no  3.00  Advanced      Novice         0   02:32:17+00:00
    15     yes  4.00  Advanced    Advanced         1   02:32:17+00:00
    40     yes  3.95    Novice    Beginner         0   02:32:17+00:00
    22     yes  3.46    Novice    Beginner         0   02:32:17+00:00
    38     yes  2.65  Advanced    Beginner         1   02:32:17+00:00
    26     yes  3.57  Advanced    Advanced         1   02:32:17+00:00
    5       no  3.44    Novice      Novice         0   02:32:17+00:00
    7      yes  2.33    Novice      Novice         1   02:32:17+00:00
    19     yes  1.98  Advanced    Advanced         0   02:32:17+00:00
    >>>
 
    # Get current timestamp value with fractional precision set to 6.
    >>> df = admissions_train.assign(current_timestamp_col=func.current_timestamp(6))
    >>> print(df)
       masters   gpa     stats programming  admitted             current_timestamp_col
    id
    5       no  3.44    Novice      Novice         0  2020-07-28 02:55:07.140000+00:00
    34     yes  3.85  Advanced    Beginner         0  2020-07-28 02:55:07.140000+00:00
    13      no  4.00  Advanced      Novice         1  2020-07-28 02:55:07.140000+00:00
    40     yes  3.95    Novice    Beginner         0  2020-07-28 02:55:07.140000+00:00
    22     yes  3.46    Novice    Beginner         0  2020-07-28 02:55:07.140000+00:00
    19     yes  1.98  Advanced    Advanced         0  2020-07-28 02:55:07.140000+00:00
    36      no  3.00  Advanced      Novice         0  2020-07-28 02:55:07.140000+00:00
    15     yes  4.00  Advanced    Advanced         1  2020-07-28 02:55:07.140000+00:00
    7      yes  2.33    Novice      Novice         1  2020-07-28 02:55:07.140000+00:00
    17      no  3.83  Advanced    Advanced         1  2020-07-28 02:55:07.140000+00:00
    >>>