temp_table_database and temp_view_database | Teradata Package for Python - 17.00 - temp_table_database and temp_view_database - Teradata Package for Python

Teradata® Package for Python User Guide

Product
Teradata Package for Python
Release Number
17.00
Published
November 2021
Last Update
2022-01-14
Content Type
User Guide
Publication ID
B700-4006-070K
Language
English (United States)
Last Update
2022-01-14

teradataml internally creates database objects (tables and views) as required while executing several functions. The temp_table_database and temp_view_database configurable options allow users to specify database names where tables and views are created, respectively. These two options give users flexibility to specify database names other than the default database to create views and tables.

The create_context function provides temp_database_name and database arguments that also allow users to specify the database name, where database objects can be created. If none of them are specified then the objects are created in users' default database.

While using these options,
  • If the configuration option temp_table_database is None, then tables are created in the database specified at the time of context creation.
  • If the configuration option temp_view_database is None, then views are created in the database specified at the time of context creation.
  • Teradata recommends using these options when following conditions are true, otherwise, use the arguments in the create_context() function:
    • When a user has permissions to create tables in one database while views in other database.
    • In case a user wishes to create these temporary objects in a database different than the one specified at the time of context creation. This allows the user to change the database name without re-creating the context.
    • In case a user forgets to use the create_context() arguments to set the temp_database_name, then use these options.

Example

>>> from teradataml import *
>>> # Set the teradataml Configuration property 'temp_table_database' True
>>> configure.temp_table_database = "tempdb"
>>> load_example_data("dataframe", "admissions_train")
>>> # Load example loads sample tables to "tempdb" database as option is set.
>>> admissions_train = DataFrame.from_table(in_schema("tempdb","admissions_train"))
>>> glm_out1 = GLM(formula = "admitted ~ stats + masters + gpa + programming",
                           family = "LOGISTIC",
                           linkfunction = "LOGIT",
                           data = admissions_train,
                           weights = "1",
                           threshold = 0.01,
                           maxit = 25,
                           step = False,
                           intercept = True
                           )
>>> # If we observe query, we can find that output table is created in "tempdb"
>>> glm_out1.output.show_query()
select * from "tempdb"."teradataml_td_glm_mle0_1623374476821412";