pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Albert REINER <areiner@tph.tuwien.ac.at>
To: PostgreSQL-SQL <pgsql-sql@postgreSQL.org>
Subject: Re: "'" in SQL INSERT statement
Date: Thu, 25 Jan 2001 18:42:37 +0100
Message-ID: <20010125184237.A1034@frithjof> (raw)
In-Reply-To: <3A6FFC12.F5ABA71@imsd.uni-mainz.de>
References: <3A6FFC12.F5ABA71@imsd.uni-mainz.de>

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                                   <areiner@tph.tuwien.ac.at>
Deutsch       *       English       *       Esperanto       *       Latine
--------------------------------------------------------------------------



view thread (7+ messages)  latest in thread

Message-ID: <20010125184237.A1034@frithjof>
Permalink:  ../20010125184237.A1034@frithjof/
Also on:    postgresql.org/message-id/20010125184237.A1034@frithjof

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: areiner@tph.tuwien.ac.at
  Subject: Re: "'" in SQL INSERT statement
  In-Reply-To: <20010125184237.A1034@frithjof>
  References: <3A6FFC12.F5ABA71@imsd.uni-mainz.de> <20010125184237.A1034@frithjof>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox