Access Tables in a Non-Default Database in Vantage - Teradata Python Package

Teradata® Python Package User Guide

Product
Teradata Python Package
Release Number
16.20
Published
February 2020
Language
English (United States)
Last Update
2020-02-29
dita:mapPath
rkb1531260709148.ditamap
dita:ditavalPath
Generic_no_ie_no_tempfilter.ditaval
dita:id
B700-4006
lifecycle
previous
Product Category
Teradata Vantage

When you create a connection to Vantage, you have the option to either specify a default database, or rely on the default database of the connecting user. However, it is also possible to interact with the tables in a database other than the default using the following approaches.

Using the in_schema() function

The in_schema() function takes a schema name and a table name and creates a database object name in the format "schema"."table_name".

Teradata recommends to use this function to access table(s) and view(s) from a database other than the default database.

The following example creates a DataFrame from the existing Vantage view "dbcinfo" in the non-default database "dbc" using the in_schema() function.

>>> from teradataml.dataframe.dataframe import in_schema
>>> df = DataFrame(in_schema("dbc", "dbcinfo"))
>>> df
                 InfoKey     InfoData
0                RELEASE  16.20.27.01
1  LANGUAGE SUPPORT MODE     Standard
2                VERSION  16.20.27.01

Using fully qualified table name

Alternatively, you can use fully qualified table name that can be passed to the from_table() function or fully qualified table in SQL that can be passed to the from_query() function.

  • Example: Using from_table() and fully qualified table name
    >>> from teradataml.dataframe.dataframe import DataFrame
    
    >>> df = DataFrame.from_table("dbc.dbcinfo")
    >>> df
                     InfoKey     InfoData
    0  LANGUAGE SUPPORT MODE     Standard
    1                RELEASE  16.20.27.01
    2                VERSION  16.20.27.01
    >>>
  • Example: Using from_query() and fully qualified table name in SQL
    >>> from teradataml.dataframe.dataframe import in_schema
    
    >>> df = DataFrame.from_query("SELECT * FROM dbc.dbcinfo")
    >>> df
                     InfoKey     InfoData
    0                RELEASE  16.20.27.01
    1  LANGUAGE SUPPORT MODE     Standard
    2                VERSION  16.20.27.01