Skip to content

Commit 9e7a921

Browse files
committed
Merge branch 'development'
2 parents 40800e0 + f181cb5 commit 9e7a921

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Development
44

5+
## 0.3.3 (2021-04-16)
6+
7+
* [#16](https://github.com/rheinwerk-verlag/postgresql-anonymizer/issues/16): Preserve column and table cases during the copy process
8+
59
## 0.3.2 (2021-01-25)
610

711
* [#15](https://github.com/rheinwerk-verlag/postgresql-anonymizer/pull/15): Fix for exclude bug ([abhinavvaidya90](https://github.com/abhinavvaidya90))

pganonymizer/utils.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def build_data(connection, table, columns, excludes, total_count, verbose=False)
7171
row[key] = value
7272
if verbose:
7373
progress_bar.next()
74-
table_columns = row.keys()
74+
table_columns = ['"{}"'.format(column) for column in row.keys()]
7575
if not row_column_dict:
7676
continue
7777
data.append(row.values())
@@ -135,18 +135,19 @@ def import_data(connection, column_dict, source_table, table_columns, primary_ke
135135
:param list data: The table data.
136136
"""
137137
primary_key = primary_key if primary_key else DEFAULT_PRIMARY_KEY
138+
temp_table = '"tmp_{table}"'.format(table=source_table)
138139
cursor = connection.cursor()
139-
cursor.execute('CREATE TEMP TABLE source(LIKE %s INCLUDING ALL) ON COMMIT DROP;' % source_table)
140-
copy_from(connection, data, 'source', table_columns)
141-
set_columns = ', '.join(['{column} = s.{column}'.format(column=key) for key in column_dict.keys()])
140+
cursor.execute('CREATE TEMP TABLE %s (LIKE %s INCLUDING ALL) ON COMMIT DROP;' % (temp_table, source_table))
141+
copy_from(connection, data, temp_table, table_columns)
142+
set_columns = ', '.join(['{column} = s.{column}'.format(column='"{}"'.format(key)) for key in column_dict.keys()])
142143
sql = (
143144
'UPDATE {table} t '
144145
'SET {columns} '
145-
'FROM source s '
146+
'FROM {source} s '
146147
'WHERE t.{primary_key} = s.{primary_key};'
147-
).format(table=source_table, primary_key=primary_key, columns=set_columns)
148+
).format(table=source_table, columns=set_columns, source=temp_table, primary_key=primary_key)
148149
cursor.execute(sql)
149-
cursor.execute('DROP TABLE source;')
150+
cursor.execute('DROP TABLE %s;' % temp_table)
150151
cursor.close()
151152

152153

pganonymizer/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# -*- coding: utf-8 -*-
22

3-
__version__ = '0.3.2'
3+
__version__ = '0.3.3'

0 commit comments

Comments
 (0)