Re: Wierd "ProgrammingError" with "E" string prefix

Karsten Hilbert <[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
On Wed, Mar 04, 2009 at 10:31:18AM -0800, Tim Roberts wrote:

> >> What version of Python are you running?  I've never seen an "E" prefix
> >> for strings in any context.
> >>     
> > It's not Python, it is PostgreSQL, and it's *inside* the
> > Python string that get's sent as the query.
> >   
> 
> I don't understand what you are saying.  Hartmut said he did this:
> 
>     curs.mogrify("SELECT %(foo)s AS foo", {'foo':'bar'} )
> and got this result
>     SELECT E'bar' AS foo
> 
> How is Postgres involved in that?  Isn't that entirely inside psycopg?

Well, the entirety of >>>SELECT E'bar' AS foo<<< is the
Python string (== the query) that is going to be sent to
PostgreSQL (if doing curs.execute(), that is).

Nonetheless, the E'bar' *inside* it is going to be
interpreted by PostgreSQL as a "string", in particular one
with C-like escapes:

	http://www.postgresql.org/docs/8.3/static/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS

That's why psycopg2 generates E''s.

Karsten
-- 
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346
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.