Re: Quote Question
| От | Michael Fuhr |
|---|---|
| Тема | Re: Quote Question |
| Дата | |
| Msg-id | 20050330171423.GA35943@winnie.fuhr.org обсуждение исходный текст |
| Ответ на | Re: Quote Question (John DeSoi <desoi@pgedit.com>) |
| Список | 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/
В списке pgsql-novice по дате отправления: