Re: Binding and custom types...

Douglas Mayle <[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
On Jun 11, 2009, at 7:03 PM, Tim Roberts wrote:

> Douglas Mayle wrote:
>> Hello all,
>>    I was wondering if someone could help me figure out an issue I'm
>> having using psycopg2 by way of SQLAlchemy because of my bind
>> parameter.  I'm running something like this:
>>
>> cursor.execute('UPDATE almanacs SET location=%(location)s,
>> modified=CURRENT_TIMESTAMP WHERE almanacs.id = %(almanacs_id)s',
>> {'almanacs_id': 2, 'location':
>> "ST_TRANSFORM
>> ('SRID=900913;01010000007f2ef1fb0b804640cdfc51710f0059c0',
>> 2163)"})
>>
>>
>> What's coming includes this: SET
>> location
>> =
>> E'ST_TRANSFORM
>> (''SRID=900913;010100000033c4b12e6e5544408f554acff48652c0'',
>> 2163)'
>>
>> Where I need it to be SET
>> location
>> =
>> ST_TRANSFORM
>> ('SRID=900913;010100000033c4b12e6e5544408f554acff48652c0',
>> 2163)
>>
>> In other words, it's a SQL function, not a text string.  Is there
>> anyway to call execute so that it won't escape my string?
>
> Yes, but only by skipping the automatic quoting.  Change the "," after
> the query string to a "%".  As long as you know there are no SQL
> injection possibilities, you don't need the automatic quoting.

Meaning I preform the string interpolation myself before calling  
cursor.execute?  Unfortunately, I don't have that choice, I'm not a  
direct consumer of psycopg, I'm using it via SQLAlchemy...

Thanks,
Doug

>
>
> -- 
> Tim Roberts, [email protected]
> Providenza & Boekelheide, Inc.
>
>
> _______________________________________________
> Psycopg mailing list
> Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
> http://lists.initd.org/mailman/listinfo/psycopg
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.