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

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -