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

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -