Utilities
check_temp_query(sql)
Checks if a query to a temporary table has had temp wrapped in quote marks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sql |
str
|
an SQL query |
required |
Source code in pydbtools/utils.py
clean_query(sql, fmt_opts=None)
removes trailing whitespace, newlines and final semicolon from sql for use with sqlparse package Args: sql (str): The raw SQL query fmt_opts (dict): Dictionary of params to pass to sqlparse.format. If None then sqlparse.format is not called. Returns: str: The cleaned SQL query
Source code in pydbtools/utils.py
replace_temp_database_name_reference(sql, database_name)
Replaces references to the user's temp database temp with the database_name string provided.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sql |
str
|
The raw SQL query as a string |
required |
database_name |
str
|
The database name to replace temp |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The new SQL query which is sent to Athena |
Source code in pydbtools/utils.py
get_database_name_from_sql(sql)
Obtains database name from SQL query for use by awswrangler.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sql |
str
|
The raw SQL query as a string |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The database table name |