From 220f055d12b9bd2ea7df7c9589341ca9f4a775d7 Mon Sep 17 00:00:00 2001 From: Guillaume Lelarge Date: Wed, 23 Feb 2011 23:02:17 +0100 Subject: [PATCH] Add a truncate option for sections. --- pgloader.1.txt | 5 +++++ pgloader/pgloader.py | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pgloader.1.txt b/pgloader.1.txt index c966043..969d1bc 100644 --- a/pgloader.1.txt +++ b/pgloader.1.txt @@ -441,6 +441,11 @@ table:: The table name of the database where to load data. +truncate:: + + +pgloader+ issues a +TRUNCATE + SQL command before + importing data. + format:: + The format data are to be found, either +text+, +csv+ or +fixed+. diff --git a/pgloader/pgloader.py b/pgloader/pgloader.py index b58332d..d52106e 100644 --- a/pgloader/pgloader.py +++ b/pgloader/pgloader.py @@ -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: