On 05/07/2015 04:35 AM, Dorian Hoxha wrote:
> He wants to dynamically pass the table name:
>
> cursor.execute("SELECT * FROM %s", (table,)) # won't work
>
How about using format()?:
http://www.postgresql.org/docs/9.4/static/functions-string.html#FUNCTIONS-STRING-FORMAT
Available 9.1+
cur.execute("select format('select * from %I', 'student_info')")
sql_str = cur.fetchone()[0]
sql_str
'select * from student_info'
--
Adrian Klaver
adrian.klaver@aklaver.com