Gerry Reno | 16 Nov 21:05 2008
Picon
Picon

psycopg for Python 3.0

The final release of Python 3.0 will happen in December 2008.
Is there a version of psycopg that works with Python 3.0?
Federico Di Gregorio | 16 Nov 22:12 2008

Re: psycopg for Python 3.0

Il giorno dom, 16/11/2008 alle 15.05 -0500, Gerry Reno ha scritto:
> The final release of Python 3.0 will happen in December 2008.
> Is there a version of psycopg that works with Python 3.0?

If they didn't changed the module interface too much it should work
almost out of the box.

federico

--

-- 
Federico Di Gregorio                         http://people.initd.org/fog
Debian GNU/Linux Developer                                fog@...
INIT.D Developer                                           fog@...
  We should forget about small efficiencies, say about 97% of the
   time: premature optimization is the root of all evil.    -- D.E.Knuth
_______________________________________________
Psycopg mailing list
Psycopg@...
http://lists.initd.org/mailman/listinfo/psycopg
Gerry Reno | 16 Nov 23:43 2008
Picon
Picon

Re: psycopg for Python 3.0

Federico Di Gregorio wrote:
Il giorno dom, 16/11/2008 alle 15.05 -0500, Gerry Reno ha scritto:
The final release of Python 3.0 will happen in December 2008. Is there a version of psycopg that works with Python 3.0?
If they didn't changed the module interface too much it should work almost out of the box. federico
Doesn't Py 3.0 handle unicode strings differently than 2.x?  So wouldn't there need to be some changes in psycopg?
_______________________________________________
Psycopg mailing list
Psycopg@...
http://lists.initd.org/mailman/listinfo/psycopg
Federico Di Gregorio | 16 Nov 23:43 2008

Re: psycopg for Python 3.0

Il giorno dom, 16/11/2008 alle 17.43 -0500, Gerry Reno ha scritto:
> Federico Di Gregorio wrote: 
> > Il giorno dom, 16/11/2008 alle 15.05 -0500, Gerry Reno ha scritto:
> >   
> > > The final release of Python 3.0 will happen in December 2008.
> > > Is there a version of psycopg that works with Python 3.0?
> > >     
> > 
> > If they didn't changed the module interface too much it should work
> > almost out of the box.
> > 
> > federico
> > 
> >   
> Doesn't Py 3.0 handle unicode strings differently than 2.x?  So
> wouldn't there need to be some changes in psycopg?

Sure. After Python 3.0 is released I'll have a look at it and fix any
issues.

federico

--

-- 
Federico Di Gregorio                         http://people.initd.org/fog
Debian GNU/Linux Developer                                fog@...
INIT.D Developer                                           fog@...
 Ubuntu is an ancient African word meaning "I can't configure Debian".
                                                     -- somewhere on IRC
_______________________________________________
Psycopg mailing list
Psycopg@...
http://lists.initd.org/mailman/listinfo/psycopg
James Henstridge | 17 Nov 01:42 2008
Picon

Re: psycopg for Python 3.0

On Mon, Nov 17, 2008 at 6:12 AM, Federico Di Gregorio <fog@...> wrote:
> Il giorno dom, 16/11/2008 alle 15.05 -0500, Gerry Reno ha scritto:
>> The final release of Python 3.0 will happen in December 2008.
>> Is there a version of psycopg that works with Python 3.0?
>
> If they didn't changed the module interface too much it should work
> almost out of the box.

There are some larger changes in the C API of Python 3.0 (e.g. objects
contain a structure containing type and ref count, rather than
directly embedding those members), but there are some compatibility
macros in Python 2.6.

I think it'd be possible to port these backward compatibility macros
back to at least Python 2.4, which would greatly reduce the amount of
code that needs changing for 3.0.

There will be some backward incompatible changes (especially in the
Python code level), so I'd recommend a separate branch for 3.0
development.  By keeping the delta between the 3.0 and 2.x branches
close, hopefully it'll be possible to merge fixes from one branch to
the other.

James.
Tim Roberts | 17 Nov 19:57 2008

Re: psycopg for Python 3.0

Gerry Reno wrote:
> Federico Di Gregorio wrote:
>> Il giorno dom, 16/11/2008 alle 15.05 -0500, Gerry Reno ha scritto:
>>   
>>> The final release of Python 3.0 will happen in December 2008.
>>> Is there a version of psycopg that works with Python 3.0?    
>>
>> If they didn't changed the module interface too much it should work
>> almost out of the box.
>>   
> Doesn't Py 3.0 handle unicode strings differently than 2.x?  So
> wouldn't there need to be some changes in psycopg?

Actually, the string handling is not all that dramatically different. 
The key is that the native string type in 3.0 is what used to be the
Unicode string type in 2.x.  The 8-bit string type is gone, replaced by
a new "byte" string type.

I think Federico is underestimating the conversion effort, but it
shouldn't be a complete rewrite.

--

-- 
Tim Roberts, timr@...
Providenza & Boekelheide, Inc.
paftek | 19 Nov 17:46 2008
Picon

Re: About mogrify

2008/9/22 Federico Di Gregorio <fog@...>:
> 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() ?

>>> curs.execute(
...     "INSERT INTO item VALUES %s" % ','.join(
...         curs.mogrify(
...             '%s',
...             [(i, 'Title %d' % i)]
...         )
...         for i in range(10)
...     )
... )
>>> print curs.query
INSERT INTO item VALUES (0, E'Title 0'),(1, E'Title 1'),(2, E'Title
2'),(3, E'Title 3'),(4, E'Title 4'),(5, E'Title 5'),(6, E'Title
6'),(7, E'Title 7'),(8, E'Title 8'),(9, E'Title 9')

Thanks,
Julien
Federico Di Gregorio | 19 Nov 18:02 2008

Re: About mogrify

On Wed, Nov 19, 2008 at 05:46:30PM +0100, paftek wrote:
> 2008/9/22 Federico Di Gregorio <fog@...>:
> > 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
paftek | 19 Nov 18:27 2008
Picon

Re: About mogrify

On Wed, Nov 19, 2008 at 6:02 PM, Federico Di Gregorio <fog@...> wrote:
> On Wed, Nov 19, 2008 at 05:46:30PM +0100, paftek wrote:
>> 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

Speed !
http://www.depesz.com/index.php/2007/07/05/how-to-insert-data-to-database-as-fast-as-possible/

I also use mogrify() to add WHERE conditions to my queries according
to what the user decides to filter on.

SELECT * FROM item
WHERE user_id = 1
    AND price > 10 -- added using mogrify()
    AND quantity > 50 -- added using mogrify()

Actually I can not live without mogrify() :)
Julien
Federico Di Gregorio | 20 Nov 10:01 2008

Re: About mogrify

Il giorno mer, 19/11/2008 alle 18.27 +0100, paftek ha scritto:
> 
> Speed !
> http://www.depesz.com/index.php/2007/07/05/how-to-insert-data-to-database-as-fast-as-possible/
> 
Ok.

> I also use mogrify() to add WHERE conditions to my queries according
> to what the user decides to filter on.
>
> SELECT * FROM item
> WHERE user_id = 1
>     AND price > 10 -- added using mogrify()
>     AND quantity > 50 -- added using mogrify()

I don't understand why you need to use mogrify() here.

federico

--

-- 
Federico Di Gregorio                         http://people.initd.org/fog
DISCLAIMER. If I receive a message from you, you are agreeing that:
 1. I am by definition, "the intended recipient".
 2. All information in the email is mine to do with as I see fit and
 make such financial profit, political mileage, or good joke as it lends
 itself to. In particular, I may quote it on USENET or the WWW.
 3. I may take the contents as representing the views of your company.
 4. This overrides any disclaimer or statement of confidentiality that
 may be included on your message.
_______________________________________________
Psycopg mailing list
Psycopg@...
http://lists.initd.org/mailman/listinfo/psycopg

Gmane