Skip to content

Instantly share code, notes, and snippets.

@risent
Created May 14, 2013 03:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save risent/5573580 to your computer and use it in GitHub Desktop.
Save risent/5573580 to your computer and use it in GitHub Desktop.
Alter postgresql sequence permission to the correct owner after migrate from mysql by py-mysql2pgsql
import psycopg2
def alter():
conn = psycopg2.connect(database='bazaar4_13', user='postgres')
cur = conn.cursor()
seq_sql = """SELECT c.relname FROM pg_class c WHERE c.relkind = 'S'"""
cur.execute(seq_sql)
seq_list = cur.fetchall()
for seq in seq_list:
field = seq[0].rsplit('_', 2)[0]
# print seq, field
sql = 'ALTER SEQUENCE %s OWNED BY %s.id' % (seq[0], field)
print sql
cur.execute(sql)
conn.commit()
conn.close()
if __name__ == "__main__":
alter()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment