Reputation: 10732
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;'
And I get output like:
Foo\015\012Bar\011This is some text.
Instead I want:
Foo
Bar This is some text.
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.
Upvotes: 2
Views: 2628
Reputation: 284
Try to convert your bytea in this way to ascii:
psql -Atc "SELECT convert_from (my_column, 'SQL_ASCII') from my_table limit 1;"
Upvotes: 4