Thread: Re: [GENERAL] Apostrophes et al in a files with text attribute

Re: [GENERAL] Apostrophes et al in a files with text attribute

From
WAGNERP@UWSTOUT.EDU
Date:
> I have passed text via a Perl CGI to my database, and tried storing text
>
> into a field with the text attribute.  Only problem is if there is an
> apostrophe in the string as in the word "can't"
> it will not INSERT.... hmm... isn't "isn't" text?
>
> hehehe.. anyways, what is the usual work around?

Since single quotes are the text delimiter, they need to be doubled up
within text.  You want to end up with something like:
    insert into table values ('This isn''t possible');

In Perl, if you have a variable containing your string, you can do
something like:

### --- Replace single quote with two single quotes for PostgreSQL
$value =~ s/\'/\'\'/g;

Hope this helps,

Paul

*************************************************************************
* Paul J. Wagner / Assistant Professor of Computer Science              *
* Department of Mathematics, Statistics, and Computer Science           *
* Harvey Hall, Room 202J; 715-232-5001                                  *
* University of Wisconsin - Stout     work   - wagnerp@uwstout.edu      *
* Menomonie, WI 54751                 school - wagner@cs.umn.edu        *
*         www - http://www.mscs.uwstout.edu/~paul/home.html             *
*************************************************************************