Variable-length binary string type in PostgreSQL
Questions tagged [bytea]
189 questions
69
votes
2 answers
Are there performance issues storing files in PostgreSQL?
Is it ok storing files like HTML pages, images, PDF, etc in a table in PostgreSQL or it is slow? I read some articles saying that this is not recommended, but I don't know if it's true.
The column types I have in mind are BLOB (as far as I know it…

Renato Dinhani
- 35,057
- 55
- 139
- 199
59
votes
2 answers
What is the datatype bytea and when would I use it?
In Postgres there is a datatype called bytea
The Postgres docs are here for it: http://www.postgresql.org/docs/9.0/static/datatype-binary.html
I cannot understand when I would ever use this - nor can I really understand the purpose of this…

Walker Farrow
- 3,579
- 7
- 29
- 51
15
votes
5 answers
How to save a image file on a Postgres database?
For learning purposes, I'm creating a site using Python+Flask. I want to recover an image from database and show it on screen. But one step at a time.
I have no idea how to save an image in my database in the first place. My searches only revealed…

Felipe Matos
- 165
- 1
- 1
- 10
14
votes
5 answers
How to read bytea image data from PostgreSQL with JPA?
I have PostgreSQL database and there is column 'image' with datatype 'bytea'. I cannot modify columns or database configurations. JPA annotated POJO contains followign mapping
@Column(name="image")
private byte[] image;
The returned data is in…

Bhushan
- 567
- 2
- 5
- 14
12
votes
3 answers
Convert PostgreSQL bytea-stored serialized-java-UUID to postgresql-UUID
One of our software-projects uses a PostgreSQL-table with a column 'guid' of type bytea.
This is used with hibernate 3.3.2.GA with PostgreSQL 8.4, which serializes the java UUID type using java object serialization. The result is a value like the…

FvHovell
- 171
- 1
- 1
- 6
9
votes
2 answers
Convert a bytea into a binary string
I need to decode a base64 string and take a chunk of binary.
Is there a SQL function in Postgres to simply convert a bytea into a binary string representation?
(Like "00010001010101010".)

GPif
- 543
- 2
- 6
- 22
7
votes
1 answer
Convert bytea to double precision in PostgreSQL
I have a database where one of the tables stores a blob (bytea) of all kinds of generic data collected from another system. The bytea field can have anything in it. In order to know how to interpret the data, the table also has a format field. I…

Keith
- 143
- 8
7
votes
1 answer
Postgres. How to convert string that contains '\' to bytea?
I have string 'test\data' or just one backslash symbol '\'.
How it convert to bytea?

marvinorez
- 593
- 4
- 7
7
votes
4 answers
Storing images in bytea fields in a PostgreSQL database
I stored an image in a PostgreSQL database with column type bytea using PHP. The problem is every time I try to load the image in a browser it does not appear. The Firefox developer console says the image is either truncated or corrupt.
The PHP…

Olayemi Odunayo
- 83
- 1
- 1
- 5
7
votes
4 answers
Convert bigint to bytea, but swap the byte order
I have a PostgreSQL table that I want to alter a column from bigint to bytea byte to hold more data. I am thinking using the following sequence:
alter table mytable add new_column
update mytable set new_column = int8send(old_column)
alter table…

Junping
- 619
- 7
- 9
6
votes
2 answers
PostgreSQL - How to insert Base64 images strings into a BYTEA column?
I have the following SQL:
CREATE TABLE Documents (
Id INT NOT NULL,
UserId INT NOT NULL,
Label CHARACTER VARYING(220) NOT NULL,
Image BYTEA NOT NULL,
PRIMARY Key(Id),
FOREIGN KEY (UserId) REFERENCES Users(Id)
);
I want to know, How…
user11150028
6
votes
1 answer
Proper way to convert bytea from Postgres back to a string in python
I have a small script where I'm generating SHA1 hashes, taking the binary representation through hashlib's hexdigest, and storing them in a Postgres DB with a bytea column. I have a query that looks like this in Postgres (abbreviated):
SELECT * FROM…

Clicquot the Dog
- 530
- 2
- 6
- 19
5
votes
2 answers
Alphanumeric Sorting in PostgreSQL
I have this table with a character varying column in Postgres 9.6:
id | column
------------
1 |IR ABC-1
2 |IR ABC-2
3 |IR ABC-10
I see some solutions typecasting the column as bytea.
select * from table order by column::bytea.
But it always…

muffin
- 2,034
- 10
- 43
- 79
5
votes
1 answer
PostgreSQL 9.X bytea representation in 'hex' or 'escape' for thumbnail images
My application (developed in Delphi and ZEOS components) uses PostgreSQL 8.4 and stores some thumbnail images into a bytea column.
I want to migrate to PostgreSQL 9.2 and have restored the dump and everything works fine except when I try to retrieve…

AndreaBoc
- 3,077
- 2
- 17
- 22
5
votes
2 answers
Store and retrieve images in Postgresql using Java
I am new to Java programming, I am searching for Java code to store images in PostgreSQL and to retrieve the image.
In PostgreSQL I have used Bytea Data-type. the image was stored. but when I retrieve I am getting NULL. I cant get the image.
Any…

MAHI
- 9,263
- 11
- 36
- 47