Skip to content

Commit ea07b91

Browse files
committed
handle schema prefix (python version)
1 parent 04b9c81 commit ea07b91

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

python/pg-dump2insert.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
import fileinput
33
import re
4-
start_table_pattern = re.compile("^COPY (\w+) \(([\w, ]+)\) FROM stdin;")
4+
5+
start_table_pattern = re.compile("^COPY ([\w\.]+) \(([\w, ]+)\) FROM stdin;")
56
table_name = None
67
fields = None
78
insert_mode = False
@@ -11,16 +12,18 @@
1112
if line == "\\.\n":
1213
insert_mode = False
1314
continue
14-
values = [ v == '\\N' and 'NULL' or "'%s'" % v \
15-
for v in line[:-1].replace("'", "''").split("\t") ]
16-
print "INSERT INTO %s (%s) VALUES (%s);" \
17-
% (table_name, fields, ", ".join(values))
15+
values = [
16+
v == "\\N" and "NULL" or "'%s'" % v
17+
for v in line[:-1].replace("'", "''").split("\t")
18+
]
19+
print(
20+
"INSERT INTO %s (%s) VALUES (%s);" % (table_name, fields, ", ".join(values))
21+
)
1822
else:
1923
start_table = start_table_pattern.match(line)
2024
if start_table:
2125
table_name = start_table.group(1)
2226
fields = start_table.group(2)
2327
insert_mode = True
2428
continue
25-
print line,
26-
29+
print(line, end=" ")

0 commit comments

Comments
 (0)