Defining Python function with input
<p>I have Postgres table called Records with several appIds. I am writing a function to pull out the data for one <code>AppId</code> (ABC0123) and want to store this result in dataframe <code>df</code>. 
I have created a variable AppId1 to store my AppId(ABC0123) and passed it to the query.
The script got executed, but it did not create the dataframe.</p>

<pre><code>def fun(AppId):
    AppId1=pd.read_sql_query(""" select "AppId" from "Records" where "AppId"='%s'""" %AppId,con=engine )
    query = """" SELECT AppId from "Records" where AppId='%s' """ % AppId1
    df=pd.read_sql_query(query,con=engine)
    return fun

fun('ABC0123')
</code></pre>

<ul>
<li>Change % AppId1 to % AppId only.</li>
<li>return df</li>
</ul>

<p></p>

<pre><code>def fun(AppId):
    AppId1=pd.read_sql_query(""" select 'AppId' from 'Records' where 'AppId'='%s'""" %AppId,con=engine )
    query = """ SELECT 'AppId' from 'Records' where AppId='%s' """ %AppId
    df=pd.read_sql_query(query,con=engine)
    return df
</code></pre>

python postgresql function