Re: "'" in SQL INSERT statement

From: "Albert REINER" <areiner(at)tph(dot)tuwien(dot)ac(dot)at>
To: PostgreSQL-SQL <pgsql-sql(at)postgreSQL(dot)org>
Subject: Re: "'" in SQL INSERT statement
Date: 2001-01-25 17:42:37
Message-ID: 20010125184237.A1034@frithjof
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)csi(dot)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 <areiner(at)tph(dot)tuwien(dot)ac(dot)at>
Deutsch * English * Esperanto * Latine
--------------------------------------------------------------------------

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Marcos Aurélio S. da Silva 2001-01-25 17:54:19 crypt and decrypt
Previous Message Kyle 2001-01-25 17:27:36 Re: Rule not invoked in 7.1