From 76f62da49c24fd8800b32366a6626a6488671b99 Mon Sep 17 00:00:00 2001 From: Austin Weisgrau Date: Fri, 20 Sep 2024 16:31:29 -0700 Subject: [PATCH] Fixes to postgres methods Don't lower-case table names Put double quotes around table name in copy statement --- parsons/databases/postgres/postgres.py | 2 +- parsons/databases/postgres/postgres_core.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/parsons/databases/postgres/postgres.py b/parsons/databases/postgres/postgres.py index 7effcc82af..87345b4143 100644 --- a/parsons/databases/postgres/postgres.py +++ b/parsons/databases/postgres/postgres.py @@ -88,7 +88,7 @@ def copy( self.query_with_connection(sql, connection, commit=False) logger.info(f"{table_name} created.") - sql = f"""COPY {table_name} ("{'","'.join(tbl.columns)}") FROM STDIN CSV HEADER;""" + sql = f"""COPY "{table_name}" ("{'","'.join(tbl.columns)}") FROM STDIN CSV HEADER;""" with self.cursor(connection) as cursor: cursor.copy_expert(sql, open(tbl.to_csv(), "r")) diff --git a/parsons/databases/postgres/postgres_core.py b/parsons/databases/postgres/postgres_core.py index 080b35a4a9..b19c69890f 100644 --- a/parsons/databases/postgres/postgres_core.py +++ b/parsons/databases/postgres/postgres_core.py @@ -226,9 +226,9 @@ def table_exists_with_connection(self, table_name, connection, view=True): # Extract the table and schema from this. If no schema is detected then # will default to the public schema. try: - schema, table = table_name.lower().split(".", 1) + schema, table = table_name.split(".", 1) except ValueError: - schema, table = "public", table_name.lower() + schema, table = "public", table_name with self.cursor(connection) as cursor: # Check in pg tables for the table