Example:
Table=["category1","category2","category3"]
for varTable in Table:
cr.execute('update varTable SET id=%s,WHERE id=%s)
........
....
How to do this loop?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use dynamic SQL for that. The default is to use plpgsql with
EXECUTE.Create a function or use a
DOstatement for ad-hoc execution.Dynamic SQL
Call:
There are lots of similar answers on SO. Search for dynamic-sql, plpgsql and
EXECUTEfor more examples and explanation.Plain SQL
If plpgsql is still black magic to you, you can solve this simple case quite effectively with a data-modifying CTE. Requires PostgreSQL 9.1 – for data-modifying CTE.