Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I read enough to know that this occurs when a string contains some characters that Postgres doesn't like. However, I cannot figure out if there is a way to validate strings before writing them. In particular, I'm doing batch inserts.

insert into foo(col1,col2,col3) values ('a',2,3),('b',4,0),....

My DB is setup like this:

   Name     | Owner  | Encoding | Collate | Ctype | Access privileges
------------+--------+----------+---------+-------+-------------------
 stats      | me     | UTF8     | C       | C     |

Periodically, some bad string will get in and the whole insert will fail(e.g. change���=). I batch up quite a few values in a single insert so I'd like to ideally validate the string rather than bomb the whole insert. Is there a list of which characters are not allowed in a Postgres insert?

Using postgresql-jdbc 9.1-901.jdbc4

share|improve this question
    
I fixed the insert statement -- I have no doubts about the insert statement itself, it worked fine until some naughty strings made it in –  Yana K. Feb 3 at 22:27
    
Did you find a way to do it? –  Matthieu Mar 27 at 9:46
1  
After reading other SO posts and looking at the string, I noticed that I had some NULL characters in there so I ended up filtering out all control characters (e.g. str.replaceAll("\\p{C}", "?");). I still don't know of official documentation of what UTF ranges are not allowed but this seemingly solved my problem. –  Yana K. Mar 28 at 15:24
    
Thanks for the update. –  Matthieu Mar 28 at 17:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.