Skip to content

Instantly share code, notes, and snippets.

@YiLi225
Created March 11, 2020 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YiLi225/896984b9c0d73a56c76902d18942ac00 to your computer and use it in GitHub Desktop.
Save YiLi225/896984b9c0d73a56c76902d18942ac00 to your computer and use it in GitHub Desktop.
import pandas as pd
def getSQL(sql_query,
place_holder_str,
replace_place_holder_with,
database_con):
'''
Args:
sql_query: sql query file
place_holder_str: string in the original sql query that is to be replaced
replace_place_holder_with: real values that should be put in
database_con: connection to the database
'''
sqlFile = open(sql_query, 'r')
sqlQuery = sqlFile.read()
sqlQuery = sqlQuery.replace(place_holder_str, replace_place_holder_with)
df = pd.read_sql_query(sqlQuery, database_con)
database_con.close()
return df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment