Created
May 14, 2013 03:57
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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