mirror of https://github.com/dbcli/pgcli
Merge pull request #133 from drocco007/master
Cast bytea fields to text for output.
This commit is contained in:
commit
591534cfc8
|
@ -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)
|
||||
|
|
|
@ -112,4 +112,13 @@ def test_multiple_queries_same_line_syntaxerror(executor):
|
|||
|
||||
@dbtest
|
||||
def test_special_command(executor):
|
||||
run(executor, '\\?')
|
||||
run(executor, '\\?')
|
||||
|
||||
|
||||
@dbtest
|
||||
def test_bytea_field_support_in_output(executor):
|
||||
run(executor, "create table binarydata(c bytea)")
|
||||
run(executor,
|
||||
"insert into binarydata (c) values (decode('DEADBEEF', 'hex'))")
|
||||
|
||||
assert u'\\xdeadbeef' in run(executor, "select * from binarydata", join=True)
|
||||
|
|
Loading…
Reference in New Issue