@@ -61,10 +61,11 @@ def main(argv):
61
61
header = None
62
62
skipRows = 0
63
63
ignoreColumns = None
64
+ tableExists = False
64
65
65
66
try :
66
67
opts , args = getopt .getopt (argv , "h:t:k:vq" , \
67
- ["help" , "verbose" , "quiet" , "header=" , "tablename=" , "output=" , "key=" , "skip=" , "ignore=" ])
68
+ ["help" , "verbose" , "quiet" , "header=" , "tablename=" , "output=" , "key=" , "skip=" , "ignore=" , "tableexists" ])
68
69
except getopt .GetoptError :
69
70
printError ("Invalid argument error" )
70
71
printUsage ()
@@ -88,15 +89,18 @@ def main(argv):
88
89
skipRows = int (arg )
89
90
elif opt in ("--ignore" ):
90
91
ignoreColumns = arg .split ("," )
91
-
92
+ elif opt in ("--tableexists" ):
93
+ tableExists = True
94
+
92
95
# print args
93
96
if len (args ) != 1 :
94
97
printUsage ()
95
98
return 1
96
99
input_filename = args [0 ]
97
100
98
101
printVerbose ("csv2sql.py - Version %s - Run date: %s" % (__version__ , time .ctime ()) )
99
- printVerbose ("Source file: %s - %d bytes - Stamped %s" % (os .path .basename (input_filename ), os .path .getsize (input_filename ), time .ctime (os .path .getmtime (input_filename ))) )
102
+ printVerbose ("Source file: %s - %d bytes - Stamped %s" \
103
+ % (os .path .basename (input_filename ), os .path .getsize (input_filename ), time .ctime (os .path .getmtime (input_filename ))) )
100
104
printVerbose ("Skipping %d row(s)" % skipRows )
101
105
102
106
input = file (input_filename ,'r' )
@@ -119,7 +123,7 @@ def main(argv):
119
123
printVerbose ("Guessing Excel CSV" )
120
124
elif (tabs > commas ):
121
125
dialect = "excel-tab"
122
- printVerbose ("Guess Excel TSV" )
126
+ printVerbose ("Guessing Excel TSV" )
123
127
124
128
# reset input file back to beginning
125
129
input .seek (0 )
@@ -130,7 +134,8 @@ def main(argv):
130
134
for i in range (skipRows ):
131
135
c .next ()
132
136
printVerbose ("Using header row: %s" % header )
133
- print createTable (header )
137
+ if not tableExists :
138
+ print createTable (header )
134
139
print "\n begin;\n "
135
140
for row in c :
136
141
print insertRow (row )
0 commit comments