From: | Andreas Joseph Krogh <andreas(at)visena(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: BYTEA |
Date: | 2016-01-18 13:06:55 |
Message-ID: | VisenaEmail.be.6d0348ce97ca0a34.15254ccbfe9@tc7-visena |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
På søndag 17. januar 2016 kl. 23:13:09, skrev Thomas Kellerer <
spam_eater(at)gmx(dot)net <mailto:spam_eater(at)gmx(dot)net>>:
Andreas Joseph Krogh schrieb am 17.01.2016 um 23:09:
> > Do I really *Need to escape/encode binary data before sending to DB
> > then do the reverse after retrieving the data?*
> > *
> > *
> > If so, what (*Java*) codes should I use to achieve this goal (I am
using
> > the Java to interface with the DB)?
>
> https://jdbc.postgresql.org/documentation/94/binary-data.html
>
> Save yourself the trouble and don't go this route. Use
https://github.com/impossibl/pgjdbc-ng instead.
Can you elaborate?
Using the "official" JDBC driver with bytea column works just fine for me.
Depends on what "works" is.
Using BLOBs (that is SQL-BLOB, not *ps.setBinaryStream etc.) with
ps.setBlob/rs.getBlob and Connection.createBlob certainly doesn't work using
the official driver.
https://github.com/pgjdbc/pgjdbc/blob/master/pgjdbc/src/main/java/org/postgresql/jdbc/PgConnection.java#L1284-L1287
public Blob createBlob() throws SQLException { checkClosed(); throw
org.postgresql.Driver.notImplemented(this.getClass(), "createBlob()"); }
AFAIU this thread is about working with LARGE OBJECTS, not only binary data.
Also, using BYTEA with LARGE objects (not just binary data) quickly leads to
OutOfMemoryError. Which is why I recommend using pgjdbc-ng and real BLOBs
(using OID) instead. It is true that get/setBinaryStream "works", in essence
that it appears to do the jobb. The problem is that despite using
get/setBinaryStream with BYTEAappears to use streams, it doesn't, and the whole
byte-array is kept in memory, both in the JAVA-appand in PG. The only way to
work with real streams all the way is using OID, not BYTEA.
But, of course, if you only work with small-ish binary data, yes - BYTEA does
the job.
-- Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
andreas(at)visena(dot)com <mailto:andreas(at)visena(dot)com>
www.visena.com <https://www.visena.com>
<https://www.visena.com>
From | Date | Subject | |
---|---|---|---|
Next Message | Andreas Joseph Krogh | 2016-01-18 13:08:04 | Re: BLOBs |
Previous Message | Karsten Hilbert | 2016-01-18 10:05:07 | Re: BYTEA |