PostgreSQL psql command line string bytea column
I have a database of images. With a table of images with two columns bytea
. I would like to query the table and see these columns to see if these records store images or not. As they are nullable columns.
Currently, when I query the DB using psql command line, the whole command line screen is blank trying to display bytes.
I have searched the web for a while and cannot find a way to display the table in a suitable way. Ideally, the first "x" characters will be displayed.
I can confirm that bytea will print if it's small enough by uploading a tiny tiny image.
This is what I see when I do: SELECT * FROM Image;
source to share
you can use the function encode
:
select encode(bytea_column, 'hex')
from image;
If you only want to see the first bytes, just use the left()
function:
select left(encode(bytea_column, 'hex'), 40)
from image;
More details in the manual:
http://www.postgresql.org/docs/current/static/functions-binarystring.html
source to share