@@ -374,15 +374,17 @@ def _resolve_query_without_cache_ctas(
374374 workgroup : Optional [str ],
375375 kms_key : Optional [str ],
376376 wg_config : _WorkGroupConfig ,
377+ alt_database : Optional [str ],
377378 name : Optional [str ],
378379 use_threads : bool ,
379380 s3_additional_kwargs : Optional [Dict [str , Any ]],
380381 boto3_session : boto3 .Session ,
381382) -> Union [pd .DataFrame , Iterator [pd .DataFrame ]]:
382383 path : str = f"{ s3_output } /{ name } "
383384 ext_location : str = "\n " if wg_config .enforced is True else f",\n external_location = '{ path } '\n "
385+ fully_qualified_name : str = f'"{ alt_database } "."{ name } "' if alt_database else f'"{ database } "."{ name } "'
384386 sql = (
385- f' CREATE TABLE " { name } " \n '
387+ f" CREATE TABLE { fully_qualified_name } \n "
386388 f"WITH(\n "
387389 f" format = 'Parquet',\n "
388390 f" parquet_compression = 'SNAPPY'"
@@ -507,6 +509,7 @@ def _resolve_query_without_cache(
507509 encryption : Optional [str ],
508510 kms_key : Optional [str ],
509511 keep_files : bool ,
512+ ctas_database_name : Optional [str ],
510513 ctas_temp_table_name : Optional [str ],
511514 use_threads : bool ,
512515 s3_additional_kwargs : Optional [Dict [str , Any ]],
@@ -538,6 +541,7 @@ def _resolve_query_without_cache(
538541 workgroup = workgroup ,
539542 kms_key = kms_key ,
540543 wg_config = wg_config ,
544+ alt_database = ctas_database_name ,
541545 name = name ,
542546 use_threads = use_threads ,
543547 s3_additional_kwargs = s3_additional_kwargs ,
@@ -575,6 +579,7 @@ def read_sql_query(
575579 encryption : Optional [str ] = None ,
576580 kms_key : Optional [str ] = None ,
577581 keep_files : bool = True ,
582+ ctas_database_name : Optional [str ] = None ,
578583 ctas_temp_table_name : Optional [str ] = None ,
579584 use_threads : bool = True ,
580585 boto3_session : Optional [boto3 .Session ] = None ,
@@ -709,6 +714,9 @@ def read_sql_query(
709714 For SSE-KMS, this is the KMS key ARN or ID.
710715 keep_files : bool
711716 Should Wrangler delete or keep the staging files produced by Athena?
717+ ctas_database_name : str, optional
718+ The name of the alternative database where the CTAS temporary table is stored.
719+ If None, the default `database` is used.
712720 ctas_temp_table_name : str, optional
713721 The name of the temporary table and also the directory name on S3 where the CTAS result is stored.
714722 If None, it will use the follow random pattern: `f"temp_table_{uuid.uuid4().hex()}"`.
@@ -820,6 +828,7 @@ def read_sql_query(
820828 encryption = encryption ,
821829 kms_key = kms_key ,
822830 keep_files = keep_files ,
831+ ctas_database_name = ctas_database_name ,
823832 ctas_temp_table_name = ctas_temp_table_name ,
824833 use_threads = use_threads ,
825834 s3_additional_kwargs = s3_additional_kwargs ,
@@ -839,6 +848,7 @@ def read_sql_table(
839848 encryption : Optional [str ] = None ,
840849 kms_key : Optional [str ] = None ,
841850 keep_files : bool = True ,
851+ ctas_database_name : Optional [str ] = None ,
842852 ctas_temp_table_name : Optional [str ] = None ,
843853 use_threads : bool = True ,
844854 boto3_session : Optional [boto3 .Session ] = None ,
@@ -967,6 +977,9 @@ def read_sql_table(
967977 For SSE-KMS, this is the KMS key ARN or ID.
968978 keep_files : bool
969979 Should Wrangler delete or keep the staging files produced by Athena?
980+ ctas_database_name : str, optional
981+ The name of the alternative database where the CTAS temporary table is stored.
982+ If None, the default `database` is used.
970983 ctas_temp_table_name : str, optional
971984 The name of the temporary table and also the directory name on S3 where the CTAS result is stored.
972985 If None, it will use the follow random pattern: `f"temp_table_{uuid.uuid4().hex}"`.
@@ -1027,6 +1040,7 @@ def read_sql_table(
10271040 encryption = encryption ,
10281041 kms_key = kms_key ,
10291042 keep_files = keep_files ,
1043+ ctas_database_name = ctas_database_name ,
10301044 ctas_temp_table_name = ctas_temp_table_name ,
10311045 use_threads = use_threads ,
10321046 boto3_session = boto3_session ,
0 commit comments