summaryrefslogtreecommitdiffstats
path: root/pgcli/pgexecute.py
diff options
context:
space:
mode:
authorDaniel Rocco <drocco@gmail.com>2015-01-21 22:50:24 -0500
committerDaniel Rocco <drocco@gmail.com>2015-01-21 22:50:24 -0500
commit52b684574e368e46b14b8a2b6d12da6c96f28a1c (patch)
tree3850b43ae3179acc3ae9d814b0367901e701c5c9 /pgcli/pgexecute.py
parent244c356116238de38bc24c21501ffc4103357e84 (diff)
Cast bytea fields to text for output.
Diffstat (limited to 'pgcli/pgexecute.py')
-rw-r--r--pgcli/pgexecute.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/pgcli/pgexecute.py b/pgcli/pgexecute.py
index daef30d9..88528546 100644
--- a/pgcli/pgexecute.py
+++ b/pgcli/pgexecute.py
@@ -13,6 +13,11 @@ _logger = logging.getLogger(__name__)
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY)
+# Cast bytea fields to text. By default, this will render as hex strings with
+# Postgres 9+ and as escaped binary in earlier versions.
+psycopg2.extensions.register_type(
+ psycopg2.extensions.new_type((17,), 'BYTEA_TEXT', psycopg2.STRING))
+
# When running a query, make pressing CTRL+C raise a KeyboardInterrupt
# See http://initd.org/psycopg/articles/2014/07/20/cancelling-postgresql-statements-python/
psycopg2.extensions.set_wait_callback(psycopg2.extras.wait_select)