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

Re: Punctuation problems.

From: Ron Johnson <ron(dot)l(dot)johnson(at)cox(dot)net>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: Punctuation problems.
Date: 2003-08-11 01:54:19
Message-ID: 1060566859.21663.11.camel@haggis (view raw or flat)
Thread:
Lists: pgsql-interfaces
On Sun, 2003-08-10 at 08:55, Alastair G. Hogge wrote:
> Hello list,
> 
> I'm using PyGreSQL to access my database to store information gathered from 
> HTML forms (using CGI). However I've run into a problem with some of the data 
> retrived.
> 
> For example say a user of my HTML form inputs their  name "Eick O'Shae".
> Now when I try to store that I get problems due the ' I think. Is there a way 
> I can store and ' in the DB? Also are there other symbols should be aware of, 
> and can I store them also? This email probably isn't making much sense as I'm 
> very tired and have been looking at this screen for hours, but any help would 
> great.

The escape character "\".  

test1=# create table foo (f text);
CREATE TABLE

test1=# insert into foo values ('x');
INSERT 17266 1

test1=# select * from foo;
 f
---
 x
(1 row)

test1=# insert into foo values ('\'x\'');
INSERT 17267 1

test1=# select * from foo;
  f
-----
 x
 'x'
(2 rows)

In Python:
>>> a = "Eick O'Shae"
>>> a1 = a.split("'")
>>> a2 = a1[0]+"\\'"+a1[1]
>>> print a2
Eick O\'Shae

-- 
+---------------------------------------------------------------+
| Ron Johnson, Jr.        Home: ron(dot)l(dot)johnson(at)cox(dot)net           |
| Jefferson, LA  USA                                            |
|                                                               |
| "Man, I'm pretty.  Hoo Hah!"                                  |
|    Johnny Bravo                                               |
+---------------------------------------------------------------+



In response to

pgsql-interfaces by date

Next:From: D'Arcy J.M. CainDate: 2003-08-11 08:09:47
Subject: Re: Punctuation problems.
Previous:From: Alastair G. HoggeDate: 2003-08-10 13:55:25
Subject: Punctuation problems.

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