@@ -131,6 +131,7 @@ def read_sql_pandas(
131131 partition_on : str | None = None ,
132132 partition_range : tuple [int , int ] | None = None ,
133133 partition_num : int | None = None ,
134+ pre_execution_queries : list [str ] | str | None = None ,
134135) -> pd .DataFrame :
135136 """
136137 Run the SQL query, download the data from database into a dataframe.
@@ -160,6 +161,7 @@ def read_sql_pandas(
160161 partition_range = partition_range ,
161162 partition_num = partition_num ,
162163 index_col = index_col ,
164+ pre_execution_queries = pre_execution_queries ,
163165 )
164166
165167
@@ -174,6 +176,7 @@ def read_sql(
174176 partition_range : tuple [int , int ] | None = None ,
175177 partition_num : int | None = None ,
176178 index_col : str | None = None ,
179+ pre_execution_query : list [str ] | str | None = None ,
177180) -> pd .DataFrame : ...
178181
179182
@@ -188,6 +191,7 @@ def read_sql(
188191 partition_range : tuple [int , int ] | None = None ,
189192 partition_num : int | None = None ,
190193 index_col : str | None = None ,
194+ pre_execution_query : list [str ] | str | None = None ,
191195) -> pd .DataFrame : ...
192196
193197
@@ -202,6 +206,7 @@ def read_sql(
202206 partition_range : tuple [int , int ] | None = None ,
203207 partition_num : int | None = None ,
204208 index_col : str | None = None ,
209+ pre_execution_query : list [str ] | str | None = None ,
205210) -> pa .Table : ...
206211
207212
@@ -216,6 +221,7 @@ def read_sql(
216221 partition_range : tuple [int , int ] | None = None ,
217222 partition_num : int | None = None ,
218223 index_col : str | None = None ,
224+ pre_execution_query : list [str ] | str | None = None ,
219225) -> mpd .DataFrame : ...
220226
221227
@@ -230,6 +236,7 @@ def read_sql(
230236 partition_range : tuple [int , int ] | None = None ,
231237 partition_num : int | None = None ,
232238 index_col : str | None = None ,
239+ pre_execution_query : list [str ] | str | None = None ,
233240) -> dd .DataFrame : ...
234241
235242
@@ -244,6 +251,7 @@ def read_sql(
244251 partition_range : tuple [int , int ] | None = None ,
245252 partition_num : int | None = None ,
246253 index_col : str | None = None ,
254+ pre_execution_query : list [str ] | str | None = None ,
247255) -> pl .DataFrame : ...
248256
249257
@@ -260,6 +268,7 @@ def read_sql(
260268 partition_num : int | None = None ,
261269 index_col : str | None = None ,
262270 strategy : str | None = None ,
271+ pre_execution_query : list [str ] | str | None = None ,
263272) -> pd .DataFrame | mpd .DataFrame | dd .DataFrame | pl .DataFrame | pa .Table :
264273 """
265274 Run the SQL query, download the data from database into a dataframe.
@@ -285,6 +294,9 @@ def read_sql(
285294 the index column to set; only applicable for return type "pandas", "modin", "dask".
286295 strategy
287296 strategy of rewriting the federated query for join pushdown
297+ pre_execution_query
298+ SQL query or list of SQL queries executed before main query; can be used to set runtime
299+ configurations using SET statements; only applicable for source "Postgres" and "MySQL".
288300
289301 Examples
290302 ========
@@ -358,6 +370,13 @@ def read_sql(
358370 raise ValueError ("Partition on multiple queries is not supported." )
359371 else :
360372 raise ValueError ("query must be either str or a list of str" )
373+
374+ if isinstance (pre_execution_query , list ):
375+ pre_execution_queries = [remove_ending_semicolon (subquery ) for subquery in pre_execution_query ]
376+ elif isinstance (pre_execution_query , str ):
377+ pre_execution_queries = [remove_ending_semicolon (pre_execution_query )]
378+ else :
379+ pre_execution_queries = None
361380
362381 conn , protocol = rewrite_conn (conn , protocol )
363382
@@ -370,6 +389,7 @@ def read_sql(
370389 queries = queries ,
371390 protocol = protocol ,
372391 partition_query = partition_query ,
392+ pre_execution_queries = pre_execution_queries ,
373393 )
374394 df = reconstruct_pandas (result )
375395
@@ -392,6 +412,7 @@ def read_sql(
392412 queries = queries ,
393413 protocol = protocol ,
394414 partition_query = partition_query ,
415+ pre_execution_queries = pre_execution_queries ,
395416 )
396417 df = reconstruct_arrow (result )
397418 if return_type in {"polars" }:
0 commit comments