postgresql - Declaring a variable in postgres from python -
i have variable value set user each time person runs query. running script in python makes call postgres database. hoping first assigning value variable in 1 piece of sql code , hoping call variable in second piece of sql code.
here current code:
first code set postgres variable:
sql_statevar=("""                    tempstate varchar:= %s               """               ,(statevar,)) cur.execute(*sql_statevar) then variable set in postgres, going call stored variable:
sqlquery=("""     select upper(b.state) state,     opentable_full b     upper(b.state)=upper(tempstate)     group upper(b.state) """) then have following code:
    outputquery = "copy({0}) stdout csv header".format(sqlquery)      open('resultsfile', 'w') f:         cur.copy_expert(outputquery, file=f) i have seen several answers regarding limitations of setting variables in postgres, new postgres, not sure if these answers need.
for example: is there way define named constant in postgresql query? 
and
 how declare local variables in postgresql?
 
 
Comments
Post a Comment