diff --git a/python/pg-dump2insert.py b/python/pg-dump2insert.py index 11de29b..99f923f 100755 --- a/python/pg-dump2insert.py +++ b/python/pg-dump2insert.py @@ -1,7 +1,8 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import fileinput import re -start_table_pattern = re.compile("^COPY (\w+) \(([\w, ]+)\) FROM stdin;") + +start_table_pattern = re.compile("^COPY ([\w\.]+) \(([\w, ]+)\) FROM stdin;") table_name = None fields = None insert_mode = False @@ -11,10 +12,13 @@ if line == "\\.\n": insert_mode = False continue - values = [ v == '\\N' and 'NULL' or "'%s'" % v \ - for v in line[:-1].replace("'", "''").split("\t") ] - print "INSERT INTO %s (%s) VALUES (%s);" \ - % (table_name, fields, ", ".join(values)) + values = [ + v == "\\N" and "NULL" or "'%s'" % v + for v in line[:-1].replace("'", "''").split("\t") + ] + print( + "INSERT INTO %s (%s) VALUES (%s);" % (table_name, fields, ", ".join(values)) + ) else: start_table = start_table_pattern.match(line) if start_table: @@ -22,5 +26,4 @@ fields = start_table.group(2) insert_mode = True continue - print line, - + print(line, end=" ")