Add a truncate option for sections.

This commit is contained in:
Guillaume Lelarge 2011-02-23 23:02:17 +01:00 committed by Dimitri Fontaine
parent 723baaefa0
commit 220f055d12
2 changed files with 13 additions and 1 deletions

View File

@ -441,6 +441,11 @@ table::
The table name of the database where to load data.
truncate::
+pgloader+ issues a +TRUNCATE <table>+ SQL command before
importing data.
format::
+
The format data are to be found, either +text+, +csv+ or +fixed+.

View File

@ -284,6 +284,13 @@ class PGLoader(threading.Thread):
if not DRY_RUN:
self.log.debug("%s: '%s'", opt, self.db.pg_options[opt])
# optionnal local option truncate
self.truncate = TRUNCATE
if config.has_option(name, 'truncate'):
self.truncate = parse_config_string(
config.get(name, 'truncate'))
self.log.debug("truncate: '%s'", self.truncate)
# optionnal local pg_options
# precedence is given to command line parsing, which is in PG_OPTIONS
from tools import parse_pg_options
@ -1184,7 +1191,7 @@ class PGLoader(threading.Thread):
return
if not DRY_RUN:
if TRUNCATE:
if self.truncate:
self.db.truncate(self.table)
if TRIGGERS: