Re: "'" in SQL INSERT statement - Mailing list pgsql-sql

From Albert REINER
Subject Re: "'" in SQL INSERT statement
Date
Msg-id 20010125184237.A1034@frithjof
Whole thread Raw
In response to "'" in SQL INSERT statement  (Markus Wagner <wagner@imsd.uni-mainz.de>)
List pgsql-sql
Saluton!

On Thu, Jan 25, 2001 at 11:12:34AM +0100, Markus Wagner wrote:
...
> Some of the data are strings containing the apostrophe "'" which I use
> as string delimiter.
> 
> How can I put these into my database using the INSERT statement?

I always use this sub:
   #   # This sub adapted from sub TEXT of mmusic by ChLorenz@csi.com, using   # advice from the pgsql-novice mailing
list(David Rugge, 1 Aug 1999).   #   # Do the necessary quoting for strings.   #   sub stdstr {     my $or = $_[0];
returnundef unless (defined($or));     $or =~ s /\\/\\\\/g;    # mmusic doesn't have this, nor does D. Rugge.     $or
=~s /\'/\\\'/g;     $or =~ s /\"/\\\"/g;     $or =~ s /%/\\%/g;      # mmusic doesn't have this.     return $or;   }
 

Obviously you also need to escape the \. I no longer remember why "
and % are needed, but I certainly did have some reason then.

Albert.


-- 

--------------------------------------------------------------------------
Albert Reiner                                   <areiner@tph.tuwien.ac.at>
Deutsch       *       English       *       Esperanto       *       Latine
--------------------------------------------------------------------------


pgsql-sql by date:

Previous
From: Jan Wieck
Date:
Subject: Re: Rule not invoked in 7.1
Next
From: Josh Berkus
Date:
Subject: Re: abstract data types?