Message-ID: From: "rlbdv (@rlbdv)" To: "pgjdbc/pgjdbc" Date: Sun, 10 Aug 2025 23:47:19 +0000 Subject: Re: [pgjdbc/pgjdbc] issue #3757: PreparedStatement.toString() fails for bytea parameters with at least 42.7.7 In-Reply-To: References: List-Id: X-GitHub-Author-Login: rlbdv X-GitHub-Comment-Id: 3172974185 X-GitHub-Comment-Type: issue_comment X-GitHub-Issue: 3757 X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-Type: comment X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/issues/3757#issuecomment-3172974185 Content-Type: text/plain; charset=utf-8 I don't know pgjdbc well enough to have a good sense whether this is a plausible fix, but it does appear to resolve the immediate concerns. In previous pgjdbc releases, a PGobject of type "bytea" and with a "\xHEX" value worked fine. It looks like what's happening now is that the string value is being passed directly to `toPGLiteral`, so this patch just adds a clause to handle it. ``` --- a/pgjdbc/src/main/java/org/postgresql/util/PGbytea.java +++ b/pgjdbc/src/main/java/org/postgresql/util/PGbytea.java @@ -182,6 +182,16 @@ public class PGbytea { * @throws IOException in case there's underflow in the input value */ public static String toPGLiteral(Object value, SqlSerializationContext context) throws IOException { + + if (value instanceof String) { + String str = (String) value; + StringBuilder sb = new StringBuilder(str.length() + 9); + sb.append("'"); + sb.append(str); + sb.append("'::bytea"); + return sb.toString(); + } + if (value instanceof byte[]) { byte[] bytes = (byte[]) value; StringBuilder sb = new StringBuilder(bytes.length * 2 + 11); ```