How can I export images from a postgreSQL database?

1.9k Views Asked by At

I have a simple data table.

Schemas>resources>tables>image_data contains the columns

image_id(integer) raw_data(bytea)

How can I export this data to files named based on the image_id? Once I figure that out I want to use the image_id to name the files based on a reference in another table.

So far I've got this:

SELECT image_id, encode(raw_data, 'hex')
  FROM resources.image_data;

It generates a csv with all the images as HEX, but I don't know what to do with it.

Data-sample:

"image_id";"encode"
166;"89504e470d0a1a0a0000000d49484452000001e0000003160806000000298 ..."
0

There are 0 best solutions below