Re: auto escaping "NULL"
Tim Roberts <[email protected]>
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Organization | Providenza & Boekelheide, Inc. |
| Message-ID | <[email protected]> |
Jacob Joseph wrote:
> As a related question, what is the correct way to use the execute(s,
> args) syntax, but *not* escape a particular variable? Not so
> infrequently, I'd like to use an argument to add an SQL command, such
> as adding to a WHERE or specifying a field.
>
The "correct" way is to use the Python % operator. The psycopg argument
substitution is only valid for field values. You can do this, for
example, this way:
sql = "INSERT INTO %(table)s (%(field)s) VALUES (%%(values)s);" % data
curs.execute( sql, data )
The %% field will be skipped on the first pass and converted to %.
--
Tim Roberts, [email protected]
Providenza & Boekelheide, Inc.