Postgres psql 输出没有转义字符的字符串 [英] Postgres psql output strings without escape characters
问题描述
我在 PostgreSQL 中有一个类型为 bytea 的列,通常包含文本数据.我想获取某一行的该列的值,换行符和制表符完好无损,而不是 psql 输出的八进制转义字符.例如,我运行:
I have a column in PostgreSQL that is of type bytea that usually has text data. I want to get the value of that column for a certain row with newlines and tabs intact rather than the octal escape characters that psql is outputting. For example, I run:
psql -Atc 'SELECT my_column from my_table limit 1;'
我得到如下输出:
Foo\015\012Bar\011This is some text.
相反,我想要:
Foo
Bar This is some text.
我意识到我可以只使用 grep,这就是我正在做的,但我想知道是否有一些简单的方法可以通过 psql 来做到这一点.我尝试将值强制转换为文本,但这似乎没有帮助.
I realize I can just use grep, which is what I'm doing, but I'm wondering if there's some simple way to do this via psql. I tried type casting the value to type text, but that didn't seem to help.
推荐答案
尝试将您的 bytea 以这种方式转换为 ascii:
Try to convert your bytea in this way to ascii:
psql -Atc "SELECT convert_from (my_column, 'SQL_ASCII') from my_table limit 1;"
这篇关于Postgres psql 输出没有转义字符的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!