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

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Package for Python
Release Number
20.00
Published
March 2024
Language
English (United States)
Last Update
2024-04-09
dita:mapPath
nvi1706202040305.ditamap
dita:ditavalPath
plt1683835213376.ditaval
dita:id
rkb1531260709148
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, enclose the schema name and table name in quotation marks ("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
    >>>