2

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.

1

1 Answer 1

4

Try to convert your bytea in this way to ascii:

psql -Atc "SELECT convert_from (my_column, 'SQL_ASCII') from my_table limit 1;"
Sign up to request clarification or add additional context in comments.

1 Comment

Clever solution. Note, however, that non-printable characters will create very "creative" outcome this way. Sqlfiddle to play with ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.