How to insert special characters in psql?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • littlemaster
    New Member
    • Apr 2010
    • 25

    How to insert special characters in psql?

    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.

    Example:

    Code:
    obj=PGconn.connect(host,port'','',dbname,username,password")
    input="Last Cron Entry is = #50 23  * * *  /ProActive/bin/Logparser_NORTEL.pl -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
    ====================
    smartctl version 5.36 [i686-pc-linux-gnu] Copyright (C) 2002-6 Bruce Allen
    Home page is http://smartmontools.sourceforge.net/";
    
    
     obj.exec("insert into hcoutputs (description) values('#{input}')")
    Attached Files
    Last edited by Niheel; Dec 14 '10, 09:20 PM.
  • rski
    Recognized Expert Contributor
    • Dec 2006
    • 700

    #2
    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
    Code:
    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)

    Comment

    Working...