this function requires postgresql 72 or later with postgresql 720 and 721 bytea type must be casted when you enable multibyte support ie insert into test _ table image values $ image _ escapedbytea postgresql 722 or later does not need cast exception is when client and backend character encoding does not match there may be multibyte stream error user must cast to bytea to avoid this error 