postgresql - python - how to properly quote sql string -
how quote string postgres sql syntax within python script uses psycopg2's cur.execute ("select .. ")
postgres sql:
select 'alter table rename ' || tablename || ' ' || regexp_replace ( tablename, '_foo$', '_bar' ) || ';' pg_tables tablename '%_foo';
within python script:
cur.execute("select 'alter table rename ' || tablename || ' ' || regexp_replace ( tablename, '_foo$', '_bar' ) || ';' pg_tables tablename '%_foo'")
simply, add line breaks:
cur.execute("select 'alter table rename ' || tablename || ' ' || \ regexp_replace ( tablename, '_foo$', '_bar' ) || ';' \ pg_tables \ tablename '%_foo'")
Comments
Post a Comment