By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,064 Members | 1,449 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,064 IT Pros & Developers. It's quick & easy.

How to insert special characters in psql?

P: 24
I am having a file, that have to be inserted into db in text data type field. I am facing issue when the file having special characters like ( ,),. Kindly check the attached file for example.

Insert query only I have used.


Expand|Select|Wrap|Line Numbers
  1. obj=PGconn.connect(host,port'','',dbname,username,password")
  2. input="Last Cron Entry is = #50 23  * * *  /ProActive/bin/ -f /Zivah/Station/CTIServer/Nortel/logs/api_`date +\%d_\%m_\%Y`.log -a >> /RemoteTShooter/Out/Content/Nortel_Parser_logs_Reports_`/sbin/ifconfig | perl -ne 'if ( m/^\s*inet (?:addr:)?([\d.]+).*?cast/ ) { print qq($1_);}'``date +\%d\%m\%Y`;touch /RemoteTShooter/Out/Status/Nortel_Parser_logs_Reports_`/sbin/ifconfig | perl -ne 'if ( m/^\s*inet (?:addr:)?([\d.]+).*?cast/ ) { print qq($1_);}'``date +\%d\%m\%Y` smartctl -Hc /dev/sda
  3. ====================
  4. smartctl version 5.36 [i686-pc-linux-gnu] Copyright (C) 2002-6 Bruce Allen
  5. Home page is";
  8.  obj.exec("insert into hcoutputs (description) values('#{input}')")
Attached Files
File Type: txt file.txt (9.1 KB, 523 views)
Dec 8 '10 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 700
I think the problem is with ' characters. The simplest solution is to double all ' characters in the string you want to insert to table.
Or you can escape the ' characters (writing \' instead of ') and use E operator like that
Expand|Select|Wrap|Line Numbers
  1. E'string you want to put into table'.
If you choose the second solution you will have to escape \ characters too (you will have to write \\%d instead of \%d)
Dec 14 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.