public inbox for [email protected]  
help / color / mirror / Atom feed
From: Pradip Parkale <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin][RM6341] CSV download quotes numeric columns
Date: Tue, 20 Apr 2021 10:54:04 +0530
Message-ID: <CAJ9T6Su2_qaty3yABdEUgrJYnJDMrJHN2YWsd-vqQSMuY9hFfw@mail.gmail.com> (raw)

Hi Hackers,

Please find the attached patch for #6341 CSV download quotes numeric
columns.
Initially, the double-precision value was getting typecast to a string.


-- 
Thanks & Regards,
Pradip Parkale
Software Engineer | EnterpriseDB Corporation


Attachments:

  [application/octet-stream] RM6341.patch (2.5K, 3-RM6341.patch)
  download | inline diff:
diff --git a/web/pgadmin/utils/driver/psycopg2/connection.py b/web/pgadmin/utils/driver/psycopg2/connection.py
index de9547322..a9d55c637 100644
--- a/web/pgadmin/utils/driver/psycopg2/connection.py
+++ b/web/pgadmin/utils/driver/psycopg2/connection.py
@@ -30,7 +30,7 @@ from pgadmin.utils.exception import ConnectionLost, CryptKeyMissing
 from pgadmin.utils import get_complete_file_path
 from ..abstract import BaseConnection
 from .cursor import DictCursor
-from .typecast import register_global_typecasters, \
+from .typecast import register_float_typecasters, register_global_typecasters,\
     register_string_typecasters, register_binary_typecasters, \
     unregister_numeric_typecasters, \
     register_array_to_string_typecasters, ALL_JSON_TYPES
@@ -462,6 +462,7 @@ class Connection(BaseConnection):
         self._set_auto_commit(kwargs)
 
         register_string_typecasters(self.conn)
+        register_float_typecasters(self.conn)
 
         if self.array_to_string:
             register_array_to_string_typecasters(self.conn)
@@ -911,6 +912,8 @@ WHERE db.datname = current_database()""")
 
         # Registering back type caster for large size data types to string
         # which was unregistered at starting
+        if any(type['type_code'] == 701 for type in self.column_info):
+            register_float_typecasters(self.conn)
         register_string_typecasters(self.conn)
         return True, gen
 
diff --git a/web/pgadmin/utils/driver/psycopg2/typecast.py b/web/pgadmin/utils/driver/psycopg2/typecast.py
index 76bb1b81f..a93a53da7 100644
--- a/web/pgadmin/utils/driver/psycopg2/typecast.py
+++ b/web/pgadmin/utils/driver/psycopg2/typecast.py
@@ -13,6 +13,7 @@ data types.
 """
 
 from psycopg2 import STRING as _STRING
+from psycopg2.extensions import FLOAT as _FLOAT
 from psycopg2.extensions import DECIMAL as _DECIMAL, encodings
 import psycopg2
 from psycopg2.extras import Json as psycopg2_json
@@ -203,6 +204,14 @@ def register_string_typecasters(connection):
         psycopg2.extensions.register_type(unicode_array_type, connection)
 
 
+def register_float_typecasters(connection):
+    # This function is to convert  pg types into decimal type
+    string_type_to_float = \
+        psycopg2.extensions.new_type(TO_STRING_NUMERIC_DATATYPES,
+                                     'TYPECAST_TO_DECIMAL', _DECIMAL)
+    psycopg2.extensions.register_type(string_type_to_float, connection)
+
+
 def register_binary_typecasters(connection):
     psycopg2.extensions.register_type(
         psycopg2.extensions.new_type(


view thread (4+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: [pgAdmin][RM6341] CSV download quotes numeric columns
  In-Reply-To: <CAJ9T6Su2_qaty3yABdEUgrJYnJDMrJHN2YWsd-vqQSMuY9hFfw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox