pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
string containing (')
5+ messages / 5 participants
[nested] [flat]

* string containing (')
@ 1999-03-20 11:38  Atika <agoswa@essex.ac.uk>
  0 siblings, 1 reply; 5+ messages in thread

From: Atika @ 1999-03-20 11:38 UTC (permalink / raw)
  To: pgsql-sql

HI!
Can anyone help,
I want to store a string into a relation that might contain an apostrophe
(').  Is there anyway around this or can I not store such strings.
Thanks for your help





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: [SQL] string containing (')
@ 1999-03-20 12:48  Bruce Momjian <maillist@candle.pha.pa.us>
  parent: Atika <agoswa@essex.ac.uk>
  0 siblings, 2 replies; 5+ messages in thread

From: Bruce Momjian @ 1999-03-20 12:48 UTC (permalink / raw)
  To: agoswa@essex.ac.uk; +Cc: pgsql-sql

> HI!
> Can anyone help,
> I want to store a string into a relation that might contain an apostrophe
> (').  Is there anyway around this or can I not store such strings.
> Thanks for your help
> 
> 
> 
> 

'\''

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: [SQL] string containing (')
@ 1999-03-20 16:06  Brian Baquiran <brianb@evoserve.com>
  parent: Bruce Momjian <maillist@candle.pha.pa.us>
  1 sibling, 0 replies; 5+ messages in thread

From: Brian Baquiran @ 1999-03-20 16:06 UTC (permalink / raw)
  To: pgsql-sql

Bruce Momjian wrote:
> 
> > HI!
> > Can anyone help,
> > I want to store a string into a relation that might contain an apostrophe
> > (').  Is there anyway around this or can I not store such strings.
> > Thanks for your help
> 
> '\''

I've always thought the proper way was to use 2 quotes ('').

Brian



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: [SQL] string containing (')
@ 1999-03-22 00:58  Peter Garner <peter_garner@yahoo.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Peter Garner @ 1999-03-22 00:58 UTC (permalink / raw)
  To: Atika <agoswa@essex.ac.uk>; pgsql-sql

Hi Atika!

You need to escape the apostrophe, in other words,

"Let's all get stoned"

must be converted to 

"Let\'s all get stoned"

Here is some java that does this :

  /**
   *  Massages a <code>String</code> parameter so that parameter is
palatable to the Database.  For
   *  example, "It's a good day!" would be converted to "It\'s a good
day!".
   *
   *  @param      string    The <code>String</code> we wish to massage
   *
   *  @return     A "fixed" version of the Argument
<code>String</code> Object
   */
  public static String fixupString ( String string )
  {
    //  Assume a worst case scenario where EVERY byte in the string
needs to be escaped, i.e. make the Length of the NEW
    //  Buffer twice the Length of the old Buffer
    char  cCurrent      = '\0'  ;
    char  carrBuffer [] = new char  [string.length () * 2]  ;
    int   nBuffIdx      = 0 ;

    for ( int n = 0 ; n < string.length () ; n++ )
    {
      cCurrent  = string.charAt ( n ) ;

      //  See if the current character is an apostrophe or an '\'.  I
think the only reliable way to escape all apostrophes
      //  and all '\' is to escape each and every one that is
encountered.  Otherwise one may not get the original Text back
      //  out of the DBMS.  For example if we have the string
"1234\'5678" and we do not alter it since the apostrophe is
      //  already escaped, we will get the string "1234'5678" when we
retrieve it FROM the DBMS!
      if ( charNeedsEscaping ( cCurrent ) )
      {
        carrBuffer [nBuffIdx++] = '\\'  ;

      } /* endif */

      carrBuffer [nBuffIdx++] = cCurrent  ;

    } /* endfor */

    String  strgReturn  = new String ( carrBuffer , 0 , nBuffIdx ) ;

    return  strgReturn  ;

  } /* static String fixupString ( String string ) */






---Atika <agoswa@essex.ac.uk> wrote:
>
> HI!
> Can anyone help,
> I want to store a string into a relation that might contain an
apostrophe
> (').  Is there anyway around this or can I not store such strings.
> Thanks for your help

==
Peace,
Peter

We are Microsoft of Borg, you will be assimilated!!!
Resistance is fut...  ***BZZZRT***  THUD!!!
[General Protection Fault in MSBorg32.DLL]
Please contact the vendor of this Borg for more information
_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: [SQL] string containing (')
@ 1999-03-22 12:35  Herouth Maoz <herouth@oumail.openu.ac.il>
  parent: Bruce Momjian <maillist@candle.pha.pa.us>
  1 sibling, 0 replies; 5+ messages in thread

From: Herouth Maoz @ 1999-03-22 12:35 UTC (permalink / raw)
  To: Brian Baquiran <brianb@evoserve.com>; pgsql-sql

At 18:06 +0200 on 20/03/1999, Brian Baquiran wrote:


> >
> > > HI!
> > > Can anyone help,
> > > I want to store a string into a relation that might contain an apostrophe
> > > (').  Is there anyway around this or can I not store such strings.
> > > Thanks for your help
> >
> > '\''
>
> I've always thought the proper way was to use 2 quotes ('').

It is the proper way, as far as compatibility to standard SQL is concerned.
Both methods are supported by PostgreSQL, though.

I have a certain grievance against PostgreSQL and its escaping mechanism,
which makes scripts written in standard SQL produce wrong results if they
have backslashes in them.

Perhaps there should be a switch, SET COMPATIBILITY or something, which
disables incompatible parses from taking place, and allows using legacy
script with little concern for the content of the strings.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma





^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~1999-03-22 12:35 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-03-20 11:38 string containing (') Atika <agoswa@essex.ac.uk>
1999-03-20 12:48 ` Bruce Momjian <maillist@candle.pha.pa.us>
1999-03-20 16:06   ` Brian Baquiran <brianb@evoserve.com>
1999-03-22 12:35   ` Herouth Maoz <herouth@oumail.openu.ac.il>
1999-03-22 00:58 Re: [SQL] string containing (') Peter Garner <peter_garner@yahoo.com>

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