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

Teradata® Package for Python User Guide

Product
Teradata Package for Python
Release Number
17.00
Published
November 2021
Language
English (United States)
Last Update
2022-01-14
dita:mapPath
bol1585763678431.ditamap
dita:ditavalPath
ayr1485454803741.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 using this function to access tables and views 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

Teradata recommends using in_schema() to create a dataframe, as shown in the previous section.

Teradata does not recommend using fully qualified table name while creating a dataframe.

If you want to continue using fully qualified table name, then the schema name and table name should be quoted, that is, "schema_name"."table_name".

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
    >>>