Currently, we are facing an issue while inserting a record in PostgresSQL. My data-type is of type TEXT. It throws an error saying Error: invalid byte sequence for encoding "UTF8": 0x00.
The data that we are trying to insert contains RTF text which contains text, image followed by again text. We also made sure there are no null values passed or inserted.
We are using **PostgresSQL **version 9.6 and 12 with an encoding set as UTF-8.
Any help would be appreciated.
The RTF data with text and images (contains special characters) should insert into PostgresSQL without any issues. Also, the data type should be of type TEXT.
CodePudding user response:
You cannot store a zero byte as part of a text string in PostgreSQL. You have two options:
remove this character from the input string if it is not required
use data type
bytea
, which is suitable for binary data
If you want to stick with text
, you should also figure out what the encoding of the file is.
CodePudding user response:
If you must use text
type, you could save it base64 encoded.
There is a space overhead in the DB of about 30% over the raw data and a modest amount of CPU in your app code to encode/decode it.