Re: Quote Question

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: John DeSoi <desoi(at)pgedit(dot)com>
Cc: Greg Lindstrom <greg(dot)lindstrom(at)novasyshealth(dot)com>, pgsql-novice(at)postgresql(dot)org
Subject: Re: Quote Question
Date: 2005-03-30 17:14:24
Message-ID: 20050330171423.GA35943@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Wed, Mar 30, 2005 at 11:22:20AM -0500, John DeSoi wrote:
> On Mar 30, 2005, at 10:31 AM, Greg Lindstrom wrote:
> >
> >2. How can I insert single (and double) ticks into my data fields?
>
> You double the quote or use \
>
> VALUES('Woman''s Health', '') or
> VALUES('Woman\'s Health', '')
>
> There should be a function in your pg Python interface to handle this
> for you.

Indeed, and if you use parameterized queries then it should happen
automagically. Is this client code or a server-side (PL/Python)
function? If client-side, which PostgreSQL driver are you using?

conn = psycopg.connect('dbname=testdb')
curs = conn.cursor()
sql = 'INSERT INTO foo (val1, val2) VALUES (%s, %s)'
val1 = "single'quote"
val2 = 'double"quote'
curs.execute(sql, (val1, val2))
conn.commit()

SELECT * FROM foo;
id | val1 | val2
----+--------------+--------------
1 | single'quote | double"quote
(1 row)

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Chris Jensen 2005-03-30 18:07:23 rpm install issues - RHE3
Previous Message John DeSoi 2005-03-30 16:22:20 Re: Quote Question