psycopg | 5 May 2007 02:28
Favicon
Gravatar

[psycopg] #184: ProgrammingError instead of DataError on PostgreSQL 22P02 invalid_text_representation

#184: ProgrammingError instead of DataError on PostgreSQL 22P02
invalid_text_representation
----------------------+-----------------------------------------------------
 Reporter:  siemer    |       Owner:  fog          
     Type:  defect    |      Status:  new          
 Priority:  normal    |   Milestone:  PSYCOPG 2.0.6
Component:  psycopg2  |     Version:  2.0.2        
 Severity:  normal    |    Keywords:               
----------------------+-----------------------------------------------------
 I don't know the current mapping from PostgreSQL errors to python
 exceptions, but psycopg2 should use the pg error class as a hint:

 -all errors beginning with 22 are DataErrors
 -all errors starting with 23 are IntegrityErrors

 See http://www.postgresql.org/docs/current/static/errcodes-appendix.html

 An example:
 >>> cursor.execute("select ''::int")
 Traceback (most recent call last):
   File "<stdin>", line 1, in ?
 psycopg2.ProgrammingError: invalid input syntax for integer: ""

 >>> sys.last_value.pgcode
 '22P02'

 Regards,
 Robert

--

-- 
(Continue reading)

johnf | 10 May 2007 06:11

strange new messages appearing

Hi,
I had a recent postgres update from SUSE (used smart to update).  But now when 
I "import psycopg2" I get the following on a std out.

Anybody know about what is this about.  

 
[14606] initpsycopg: initializing psycopg 2.0.6b1 (dec dt ext pq3)
[14606] typecast_init: initializing NUMBER
[14606] typecast_new: new type at = 0x817a220, refcnt = 1
[14606] typecast_new: typecast object created at 0x817a220
[14606] typecast_add: object at 0x817a220, values refcnt = 2
[14606] typecast_add:     adding val: 20
[14606] typecast_add:     adding val: 23
[14606] typecast_add:     adding val: 21
[14606] typecast_add:     adding val: 701
[14606] typecast_add:     adding val: 700
[14606] typecast_add:     adding val: 1700
[14606] typecast_add:     base caster: (nil)
[14606] typecast_init: initializing LONGINTEGER
[14606] typecast_new: new type at = 0x817a240, refcnt = 1
[14606] typecast_new: typecast object created at 0x817a240
[14606] typecast_add: object at 0x817a240, values refcnt = 2
[14606] typecast_add:     adding val: 20
[14606] typecast_add:     base caster: (nil)
[14606] typecast_init: initializing INTEGER
[14606] typecast_new: new type at = 0x817a280, refcnt = 1
[14606] typecast_new: typecast object created at 0x817a280
[14606] typecast_add: object at 0x817a280, values refcnt = 2
[14606] typecast_add:     adding val: 23
(Continue reading)

Federico Di Gregorio | 10 May 2007 11:50
Favicon
Gravatar

Re: strange new messages appearing

Il giorno mer, 09/05/2007 alle 21.11 -0700, johnf ha scritto:
> I had a recent postgres update from SUSE (used smart to update).  But now when 
> I "import psycopg2" I get the following on a std out. 

Debug output. Remove PSYCOPG_DEBUG from setup.cfg and rebuild.

--

-- 
Federico Di Gregorio                         http://people.initd.org/fog
Debian GNU/Linux Developer                                fog@...
INIT.D Developer                                           fog@...
 Come sai se il primo è ben dato? In realtà è "Beh il secondo bacio ben
  dato non si rifiuta".                                    -- Alessandra
_______________________________________________
Psycopg mailing list
Psycopg@...
http://lists.initd.org/mailman/listinfo/psycopg
johnf | 10 May 2007 18:53

Re: strange new messages appearing

On Thursday 10 May 2007 02:50, Federico Di Gregorio wrote:
> Il giorno mer, 09/05/2007 alle 21.11 -0700, johnf ha scritto:
> > I had a recent postgres update from SUSE (used smart to update).  But now
> > when I "import psycopg2" I get the following on a std out.
>
> Debug output. Remove PSYCOPG_DEBUG from setup.cfg and rebuild.
The only 'PSYCOPG_DEBUG' I could find was in the 'define' of setup.cfg.  I 
removed it and did the following:
#python setup.py build
#python setup.py install

And I still have the messages?
--

-- 
John Fabiani
johnf | 11 May 2007 03:41

Please help with these messages

On Thursday 10 May 2007 09:53, johnf wrote:
I'm still getting messages:

[5877] initpsycopg: initializing psycopg 2.0.6b1 (dec dt ext pq3)
[5877] typecast_init: initializing NUMBER
[5877] typecast_new: new type at = 0x817a220, refcnt = 1
[5877] typecast_new: typecast object created at 0x817a220
[5877] typecast_add: object at 0x817a220, values refcnt = 2
[5877] typecast_add:     adding val: 20
[5877] typecast_add:     adding val: 23
[5877] typecast_add:     adding val: 21
[5877] typecast_add:     adding val: 701
[5877] typecast_add:     adding val: 700
[5877] typecast_add:     adding val: 1700
[5877] typecast_add:     base caster: (nil)
[5877] typecast_init: initializing LONGINTEGER
[5877] typecast_new: new type at = 0x817a240, refcnt = 1
[5877] typecast_new: typecast object created at 0x817a240
[5877] typecast_add: object at 0x817a240, values refcnt = 2
[5877] typecast_add:     adding val: 20
[5877] typecast_add:     base caster: (nil)
[5877] typecast_init: initializing INTEGER
[5877] typecast_new: new type at = 0x817a280, refcnt = 1
[5877] typecast_new: typecast object created at 0x817a280
[5877] typecast_add: object at 0x817a280, values refcnt = 2
[5877] typecast_add:     adding val: 23
[5877] typecast_add:     adding val: 21
[5877] typecast_add:     base caster: (nil)
[5877] typecast_init: initializing FLOAT
[5877] typecast_new: new type at = 0x817a2c0, refcnt = 1
(Continue reading)

Federico Di Gregorio | 11 May 2007 10:47
Favicon
Gravatar

Re: strange new messages appearing

Il giorno gio, 10/05/2007 alle 09.53 -0700, johnf ha scritto:
> The only 'PSYCOPG_DEBUG' I could find was in the 'define' of
> setup.cfg.  I 
> removed it and did the following:

Add:

#python setup.py clean -a

before rebuilding.

> #python setup.py build
> #python setup.py install

(And please stop posting the debug trace to the list.)

 
--

-- 
Federico Di Gregorio                         http://people.initd.org/fog
Debian GNU/Linux Developer                                fog@...
INIT.D Developer                                           fog@...
  Gli esseri umani, a volte, sono destinati, per il solo fatto di
   esistere, a fare del male a qualcuno.              -- Haruki Murakami
_______________________________________________
Psycopg mailing list
Psycopg@...
http://lists.initd.org/mailman/listinfo/psycopg
(Continue reading)

David Rushby | 11 May 2007 15:05
Picon

COPY FROM/TO support not flexible enough

I want to use "COPY tablename FROM STDIN WITH BINARY" to load a high
volume of data efficiently into PG.  Of course, my client code will
transform the input data into the PGCOPY binary format, but then I
need to submit that buffer to PG.

Having read the source code for Cursor.copy_from
(cursor_type.c:psyco_curs_copy_from and pqpath.c:_pq_copy_in_v3), it
appears that PsycoPG currently supports only a few variants of the
COPY FROM statement.  The specific variant that I need is not among
them.

It appears to me that the most flexible way to extend support for COPY
FROM/TO is to leave the current Cursor.copy_from and Cursor.copy_to
methods as they are, but add a Cursor.copy_expert method that accepts
a prefabricated COPY FROM/TO statement (as a Python string) and a
file-like object (anything with a read(...) method for COPY FROM;
anything with a write(...) method for COPY TO).

Client code then might look like this:
-----------------------------------------------------
fileObj = file(path, 'rb')
cursor.copy_expert("COPY tableName FROM STDIN WITH BINARY", fileObj)
-----------------------------------------------------
or, for output, like this:
-----------------------------------------------------
fileObj = file(path, 'wb')
cursor.copy_expert("COPY tableName TO STDOUT WITH BINARY", fileObj)
-----------------------------------------------------

This would allow users to formulate their own COPY FROM/TO statements.
(Continue reading)

johnf | 11 May 2007 15:38

Re: strange new messages appearing

On Friday 11 May 2007 01:47, Federico Di Gregorio wrote:
> Il giorno gio, 10/05/2007 alle 09.53 -0700, johnf ha scritto:
> > The only 'PSYCOPG_DEBUG' I could find was in the 'define' of
> > setup.cfg.  I
> > removed it and did the following:
>
> Add:
>
> #python setup.py clean -a
>
> before rebuilding.
>
> > #python setup.py build
> > #python setup.py install
>
> (And please stop posting the debug trace to the list.)
You got it.  
--

-- 
John Fabiani
VL | 11 May 2007 23:44

Connection timeout

Is there a way to set the connection string in the dsn to timeout after 
a specified amount of time?  I was looking in the archives and only 
found this.

---
import os
os.environ['PGCONNECT_TIMEOUT'] = '5'

Then my connection stuff.

---

But I want to do it for a specific connection and not all connections.  
Any ideas?

Thanks,
    Greg
Federico Di Gregorio | 12 May 2007 15:59
Favicon
Gravatar

Re: COPY FROM/TO support not flexible enough

Il giorno ven, 11/05/2007 alle 17.05 +0400, David Rushby ha scritto:
>   - Is the proposed design sound, or is there a better way?
>   - Are you receptive to an implementation from me?  If yes, on which
> branch should I implement it? 

I think it is a nice idea and I'll surely accept patches. Please diff
against the 2_0_x branch.

federico

--

-- 
Federico Di Gregorio                         http://people.initd.org/fog
Debian GNU/Linux Developer                                fog@...
INIT.D Developer                                           fog@...
                              Viviamo in un mondo reale, Ciccio. -- Lucy
_______________________________________________
Psycopg mailing list
Psycopg@...
http://lists.initd.org/mailman/listinfo/psycopg

Gmane