Re: About mogrify

Federico Di Gregorio <fog-NGVKUo/i/[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
On Wed, Nov 19, 2008 at 05:46:30PM +0100, paftek wrote:
> 2008/9/22 Federico Di Gregorio <fog-NGVKUo/i/[email protected]>:
> > Il giorno lun, 22/09/2008 alle 12.54 +0200, Oswaldo Hernández ha
> > scritto:
> >>
> >> . Question 2:
> >> In an old message (01/30/2007) Federico says:
> >>  > is there for DEBUG ONLY. There's really no reason to use .mogrify() directly; .execute() and
> >>  > psycopg2.extensions.adapt() should be enough for almost any need.
> >>
> >> It's safe the use of mogrify() directly?
> >
> > mogrify() is currently safe but you should not use it anyway because
> > there is no guarantee that it will _always_ be safe. .execute()
> > and .adapt() will never change semantics and .mogrify() is there only
> > because one sometimes need to see a query without looking at the
> > database logs (like if you don't have direct shell access to a remote
> > server). In theory you don't need .mogrify() at all: if you feel like
> > you need it, please explain why and I'll try to find a better way to do
> > the same thing or, if mogify() is really needed I'll fix psycopg API to
> > support what you need.
> 
> Actually I am using mogrify() to generate multi rows INSERT statements
> from a list of values :
> Is there a better way to do this without mogrify() ?

You can use executemany() but it will generate multiple INSERT
statements while you use a single multi-row statement. There is
any good reason to use multi row instead of using psycopg's
executemany()?

federico
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.