Use the db_list_tables() function to list tables and views from a specified schema.
- schema_name specifies the name of a database. If a database is not specified, the function lists tables from the current database. Default value is None.
- object_name specifies a table or view name or pattern to be used for filtering the list of objects. Pattern may contain '%' or '_' as pattern matching characters:
- A '%' represents any string of zero or more arbitrary characters. Any string of characters is acceptable as replacement for the percent sign.
For example: '%abc' will return all table and view object names starting with any character and ending with 'abc'.
- A '_' represents exactly one arbitrary character. Any single character is acceptable in the position in which the underscore sign appears.
For example: 'a_c' will return all table and view object names starting with 'a', ending with 'c' and has length of 3.
- A '%' represents any string of zero or more arbitrary characters. Any string of characters is acceptable as replacement for the percent sign.
- Object_type specifies object type to apply the filter. Valid value includes:
- all: list all the object types, which is the default value
- table: list only tables
- view: list only views
- volatile: list only volatile tables
- temp: list all teradataml temporary objects created in the specified database
Example 1: List all the objects in the default schema
>>> load_example_data("dataframe", "admissions_train")
>>> db_list_tables()
Example 2: List all the views in the default schema
>>> connection_object.execute("create view temporary_view as (select 1 as dummy_col1, 2 as dummy_col2);")
>>> db_list_tables(None , None, 'view')
Example 3: List all the objects in the default schema with specific conditions
This example lists all the objects in the default schema whose names begin with 'abc' followed by one arbitrary character and any number of characters in the end.
>>> connection_object.execute("create view abcd123 as (select 1 as dummy_col1, 2 as dummy_col2);")
>>> db_list_tables(None, 'abc_%', None)
Example 4: List all the tables in the default schema with specific conditions
This example lists all the tables in the default schema whose names begin with 'adm' followed by one arbitrary character and any number of characters in the end.
>>> load_example_data("dataframe", "admissions_train")
>>> db_list_tables(None, 'adm_%', 'table')
Example 5: List all the views in the default schema with specific conditions
This example lists all the views in the default schema whose names begin with any character but end with 'abc'.
>>> connection_object.execute("create view view_abc as (select 1 as dummy_col1, 2 as dummy_col2);")
>>> db_list_tables(None, '%abc', 'view')
Example 6: List all the volatile tables in the default schema with specific conditions
This example lists all the volatile tables in the default schema whose names begin with 'abc' and ends with any arbitrary character and has a length of 4.
>>> connection_object.execute("CREATE volatile TABLE abcd(col0 int, col1 float) NO PRIMARY INDEX;")
>>> db_list_tables(None, 'abc_', 'volatile')
Example 7: List all the temporary objects created by teradataml in the default schema with specific conditions
This example lists all the temporary objects created by teradataml in the default schema whose names begin and end with any number of arbitrary characters but contains 'filter' in between.
>>> db_list_tables(None, '%filter%', 'temp')