Skip to content

Commit

Permalink
Merge e384733 into 636815c
Browse files Browse the repository at this point in the history
  • Loading branch information
nvictor committed Jun 13, 2018
2 parents 636815c + e384733 commit 80188c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 8 additions & 3 deletions csvkit/utilities/csvsql.py
Expand Up @@ -53,6 +53,8 @@ def add_arguments(self):
help='Limit CSV dialect sniffing to the specified number of bytes. Specify "0" to disable sniffing entirely.')
self.argparser.add_argument('-I', '--no-inference', dest='no_inference', action='store_true',
help='Disable type inference when parsing the input.')
self.argparser.add_argument('--chunk-size', dest='chunk_size', type=int,
help='Optional chunk size. Only valid when --insert is specified.')

def main(self):
if sys.stdin.isatty() and not self.args.input_paths:
Expand Down Expand Up @@ -85,9 +87,11 @@ def main(self):
if self.args.overwrite and not self.args.insert:
self.argparser.error('The --overwrite option is only valid if --insert is also specified.')
if self.args.before_insert and not self.args.insert:
self.argparser.error('The --before_insert option is only valid if --insert is also specified.')
self.argparser.error('The --before-insert option is only valid if --insert is also specified.')
if self.args.after_insert and not self.args.insert:
self.argparser.error('The --after_insert option is only valid if --insert is also specified.')
self.argparser.error('The --after-insert option is only valid if --insert is also specified.')
if self.args.chunk_size and not self.args.insert:
self.argparser.error('The --chunk-size option is only valid if --insert is also specified.')

if self.args.no_create and self.args.create_if_not_exists:
self.argparser.error('The --no-create and --create-if-not-exists options are mutually exclusive.')
Expand Down Expand Up @@ -164,7 +168,8 @@ def _failsafe_main(self):
prefixes=self.args.prefix,
db_schema=self.args.db_schema,
constraints=not self.args.no_constraints,
unique_constraint=self.unique_constraint
unique_constraint=self.unique_constraint,
chunk_size=self.args.chunk_size
)

if self.args.after_insert:
Expand Down
6 changes: 4 additions & 2 deletions docs/scripts/csvsql.rst
Expand Up @@ -17,7 +17,7 @@ Generate SQL statements for a CSV file or execute those statements directly on a
[--prefix PREFIX] [--tables TABLE_NAMES] [--no-constraints]
[--unique-constraint UNIQUE_CONSTRAINT] [--no-create]
[--create-if-not-exists] [--overwrite] [--db-schema DB_SCHEMA]
[-y SNIFF_LIMIT] [-I]
[-y SNIFF_LIMIT] [-I] [--chunk-size NUM]
[FILE [FILE ...]]

Generate SQL statements for one or more CSV files, or execute those statements
Expand Down Expand Up @@ -65,7 +65,9 @@ Generate SQL statements for a CSV file or execute those statements directly on a
Limit CSV dialect sniffing to the specified number of
bytes. Specify "0" to disable sniffing entirely.
-I, --no-inference Disable type inference when parsing the input.

--chunk-size NUM
Chunk size for batch insert into the table.
Only valid when --insert is specified.

See also: :doc:`../common_arguments`.

Expand Down

0 comments on commit 80188c4

Please sign in to comment.