Skip site navigation (1) Skip section navigation (2)

Re: Please HELP: insert row ...

From: "Albert REINER" <areiner(at)tph(dot)tuwien(dot)ac(dot)at>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Please HELP: insert row ...
Date: 2000-10-14 14:47:04
Message-ID: 20001014164704.A407@frithjof (view raw or flat)
Thread:
Lists: pgsql-novice
On Sat, Oct 14, 2000 at 04:15:11AM +0000, Thu Huynh wrote:
> Hello,
> 
> Does anyone know how to insert/update data that contains single quote (') 
> into a field? Data such as: John's house is in Dalas.

Via Perl, I always wrap any strings with the following sub (adapted
from a similar sub of mmusic by ChLorenz(at)csi(dot)com, and incorporating
advice from this list (David Rugge, 1 Aug 1999, and some
experimentation).

sub stdstr {
    my $or = $_[0];
    $or =~ s /\\/\\\\/g;
    $or =~ s /\'/\\\'/g;
    $or =~ s /\"/\\\"/g;
    $or =~ s /%/\\%/g;
    return $or;
}

Basically you have to quote \ ' " % (even though I am no longer sure
about the reasons for some of these; but quoting certainly cannot do
any harm). Works for me.

HTH,

Albert.


-- 

--------------------------------------------------------------------------
Albert Reiner                                   <areiner(at)tph(dot)tuwien(dot)ac(dot)at>
Deutsch       *       English       *       Esperanto       *       Latine
--------------------------------------------------------------------------

In response to

pgsql-novice by date

Next:From: Thu HuynhDate: 2000-10-14 19:45:46
Subject: HELP:insert character return?
Previous:From: Charles CurleyDate: 2000-10-14 13:23:32
Subject: Re: Please HELP: insert row ...

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group