Received: from frithjof.reiner (a119.dialin.tuwien.ac.at [192.35.240.129]) by mail.postgresql.org (8.11.1/8.11.1) with SMTP id f0QH2sq23334 for ; Fri, 26 Jan 2001 12:02:56 -0500 (EST) (envelope-from areiner@tph.tuwien.ac.at) Received: (qmail 1391 invoked by uid 500); 25 Jan 2001 17:42:37 -0000 From: "Albert REINER" Date: Thu, 25 Jan 2001 18:42:37 +0100 To: PostgreSQL-SQL Subject: Re: "'" in SQL INSERT statement Message-ID: <20010125184237.A1034@frithjof> Mail-Followup-To: PostgreSQL-SQL References: <3A6FFC12.F5ABA71@imsd.uni-mainz.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <3A6FFC12.F5ABA71@imsd.uni-mainz.de>; from wagner@imsd.uni-mainz.de on Thu, Jan 25, 2001 at 11:12:34AM +0100 X-Archive-Number: 200101/381 X-Sequence-Number: 1054 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]; return undef 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 Deutsch * English * Esperanto * Latine --------------------------------------------------------------------------