Billy G. Allie | 2 Dec 2003 07:16
Picon

Re: Exception: "VACUUM cannot run inside a BEGIN/END block"

Adam Buraczewski wrote:
On Sat, Nov 29, 2003 at 06:13:35PM +0100, Karsten Hilbert wrote:
cursor.execute('end;vacuum analyze;begin;') we use this successfully around "create database"
Don't you have a feeling it's a bit ugly? ;-) DBI, and especially cursor objects, weren't invented for DDL commands, only for DMLs. Personally, I think that DBI spec should be somehow enhanced so that it would cover such situations. As an acceptable solution I usually use plain libpq module here. The goal can be achieved with following code: from pyPgSQL import PgSQL conn = PgSQL.connect(...) ... conn.conn.query("vacuum analyze") Of course it will work with pyPgSQL only :^) Best regards,
Actually, you can just set autocommit to on (per the DB-API spec it's off by default).  If autocommit is on, then pyPgSQL won't wrap the query within a begin ... end block.
from pyPgSQL import PgSQL conn - PgSQL.connect(...) conn.autocommit = 1 curs = conn.cursor() curs.execute("vacuum analyze")
Note: You must set autocommit to 0 before creating any cursors.

Of course, using the libpq.conn.query method as suggested by Adam avoids the need to create a cursor object, but you still need to be sure that there are no open cursors for the connection when you use (opening a connection with autocommit == 0 will open a transaction at cursor creations time).

Rene Pijlman | 2 Dec 2003 12:10
Picon

Re: Exception: "VACUUM cannot run inside a BEGIN/END block"

Billy G. Allie:
>Of course, using the libpq.conn.query method as suggested by Adam avoids 
>the need to create a cursor object, but you still need to be sure that 
>there are no open cursors for the connection when you use (opening a 
>connection with autocommit == 0 will open a transaction at cursor 
>creations time).

I see. I'm doing vacuum halfway through my algorithm (after
batch inserts/updates, before selects) and I'm beginning to
think its best to do the vacuum on a separate connection with
autocommit enabled.

--

-- 
Regards / Groeten,  http://www.leren.nl
René Pijlman        http://www.applinet.nl

-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
Paul Komarek | 13 Dec 2003 23:12
Picon
Favicon

Buliding on SuSE 8 for x86_64 (AMD Opteron)

Hi,

SuSE 8 for x86_64 has /usr/lib for 32 bit stuff, and /usr/lib64 for 64
bit stuff.  /usr/bin/python is 64 bit.  There is /usr/lib64/libpq.so.3
and /usr/lib/libpq.so.2.  You can imagine the mess this makes for
distutils.

I sucessfully compiled and installed pyPgSQL 2.4.0 from the source
tarball.  I made the following customizations:

1) Using the CUSTOM stuff in setup.py, set library_dirs = ["/usr/lib64",
"/usr/lib"]

2) After installing with python setup.py instal, stuff gets installed in
/usr/lib/python2.2/site-packages and you are warned this isn't in the
search path.  Simply cp -a /usr/lib/python2.2/site-packages/pyPgSQL to
/usr/lib64/python2.2/site-packages/.

I figure distutils may be able to do this kind of thing automatically.
Today is the first time I looked into distutils, and I'm not going to
mess around with fancy automatic stuff.

egenix mxDateTime also gave me some grief because their configuration
isn't documented and isn't as nice as yours.  To make it work, I edited
mxSetup.py (which I think gets copied around, so modify all copies you
find in the tarball before building).  The change is again simple:

1) search for /usr/local/lib in mxSetup.py
2) prepend '/usr/local/lib64' and '/usr/lib64' to the default library
list.

After building and installing, cp -a /usr/lib/python2.2/site-packages/mx
/usr/lib64/python2.2/site-packages.

To make this email easier to find, I'll include the error messages you
get if you don't do this stuff:

/usr/lib64/gcc-lib/x86_64-suse-linux/3.2.2/../../../../x86_64-suse-linux/bin/ld: cannot find /lib/libc.so.6
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1

The same errors occur for egenix-mx-base (for which I didn't find a good
email list to post this to).

Note that I am not subscribed to this list.  If someone feels the need
to get my attention, you can email me at komarek@...

-Paul Komarek

-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
Ivar Zarans | 15 Dec 2003 00:02
Picon

PgNumeric and NULL values

Hello!

I am playing around with PyPgSQL and found interesting behaviour:
Updating numeric field with values of '0.00' generates query, trying
update with 'NULL'. Since column is defined as 'NOT NULL', update fails
with exception:
"OperationalError: ERROR:  ExecUpdate: Fail to add null value in not
null attribute... "

Is this normal?

--

-- 
Best regards,
Ivar Zarans

-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
Ivar Zarans | 14 Dec 2003 23:46
Picon

PgNumeric and NULL values

Hello!

I am playing around with PyPgSQL and found interesting behaviour:
Updating numeric field with values of '0.00' generates query, trying
update with 'NULL'. Since column is defined as 'NOT NULL', update fails
with exception:
"OperationalError: ERROR:  ExecUpdate: Fail to add null value in not null
attribute... "

Is this normal? 

--

-- 
Best regards,
Ivar Zarans

-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
Paul Komarek | 14 Dec 2003 18:36
Picon
Favicon

Re: Buliding on SuSE 8 for x86_64 (AMD Opteron)

On Sat, 2003-12-13 at 17:12, Paul Komarek wrote:
> Hi,
> 
> SuSE 8 for x86_64 has /usr/lib for 32 bit stuff, and /usr/lib64 for 64
> bit stuff.  /usr/bin/python is 64 bit.  There is /usr/lib64/libpq.so.3
> and /usr/lib/libpq.so.2.  You can imagine the mess this makes for
> distutils.
> 
> I sucessfully compiled and installed pyPgSQL 2.4.0 from the source
> tarball.  I made the following customizations:
> 
> 1) Using the CUSTOM stuff in setup.py, set library_dirs = ["/usr/lib64",
> "/usr/lib"]
> 
> 2) After installing with python setup.py instal, stuff gets installed in
> /usr/lib/python2.2/site-packages and you are warned this isn't in the
> search path.  Simply cp -a /usr/lib/python2.2/site-packages/pyPgSQL to
> /usr/lib64/python2.2/site-packages/.
> 
> I figure distutils may be able to do this kind of thing automatically.
> Today is the first time I looked into distutils, and I'm not going to
> mess around with fancy automatic stuff.
> 
> egenix mxDateTime also gave me some grief because their configuration
> isn't documented and isn't as nice as yours.  To make it work, I edited
> mxSetup.py (which I think gets copied around, so modify all copies you
> find in the tarball before building).  The change is again simple:
> 
> 1) search for /usr/local/lib in mxSetup.py
> 2) prepend '/usr/local/lib64' and '/usr/lib64' to the default library
> list.
> 
> After building and installing, cp -a /usr/lib/python2.2/site-packages/mx
> /usr/lib64/python2.2/site-packages.
> 
> To make this email easier to find, I'll include the error messages you
> get if you don't do this stuff:
> 
> /usr/lib64/gcc-lib/x86_64-suse-linux/3.2.2/../../../../x86_64-suse-linux/bin/ld: cannot
find /lib/libc.so.6
> collect2: ld returned 1 exit status
> error: command 'gcc' failed with exit status 1
> 
> The same errors occur for egenix-mx-base (for which I didn't find a good
> email list to post this to).
> 
> Note that I am not subscribed to this list.  If someone feels the need
> to get my attention, you can email me at komarek@...
> 
> -Paul Komarek

I should mention that there's a /lib in the egenix mxSetup.py library
lists that needs to be preceded by /lib64, too.

-Paul Komarek

-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
Billy G. Allie | 15 Dec 2003 02:53
Picon

Re: PgNumeric and NULL values


Ivar Zarans wrote:
| Hello!
|
| I am playing around with PyPgSQL and found interesting behaviour:
| Updating numeric field with values of '0.00' generates query, trying
| update with 'NULL'. Since column is defined as 'NOT NULL', update fails
| with exception:
| "OperationalError: ERROR:  ExecUpdate: Fail to add null value in not
| null attribute... "
|
| Is this normal?
|

Can you post sample code that exhibits this behavior please.

Thanks.

--
____       | Billy G. Allie    | Domain....: Bill.Allie@...
|  /|      | 7436 Hartwell     | MSN.......: B_G_Allie@...
|-/-|----- | Dearborn, MI 48126|
|/  |LLIE  | (313) 582-1540    |
Shawn Harrison | 15 Dec 2003 04:08

Postgres 7.4

Hi, folks,
 
I just began using pyPgSQL with my current postgres (7.2) and would like to upgrade to pg 7.4. I read in the docs somewhere that pyPgSQL is not tested with pg 7.4, and when I tried to set it up I got  a couple of errors.
 
What is the status of porting to pg 7.4? I could re-try the setup and post the error reports, if that would be helpful.
 
Shawn Harrison
Ivar Zarans | 15 Dec 2003 11:07
Picon

Re: PgNumeric and NULL values

On Sun, Dec 14, 2003 at 08:53:33PM -0500, Billy G. Allie wrote:

> | Updating numeric field with values of '0.00' generates query, trying
> | update with 'NULL'. Since column is defined as 'NOT NULL', update fails
> 
> Can you post sample code that exhibits this behavior please.

Creaed table as:
create table testtable (
    ident int not null,
    price numeric not null
);

Inserted test values:
insert into testtable (ident, price) values (10, 0.00);

Running follofing short test:
====
#!/usr/bin/env python

from pyPgSQL import PgSQL

connstr = '::DBname:DBuser:DBpass:'
DBConn = PgSQL.connect(connstr)
Cursor = DBConn.cursor()

price = PgSQL.PgNumeric('0.00')
ident = 10

qry = """
UPDATE
    testtable
SET
    price = %s
WHERE
    ident = %s
"""

Cursor.execute(qry, price, ident)
====

throws exception:

====
Traceback (most recent call last):
  File "./numtest.py", line 21, in ?
      Cursor.execute(qry, price, ident)
  File "/usr/lib/python2.3/site-packages/pyPgSQL/PgSQL.py", line 3072,
                in execute
      raise OperationalError, msg
      libpq.OperationalError: ERROR:  ExecUpdate: 
                Fail to add null value in not null attribute price
====

PostgreSQL log has following query:

====
postgres[23448]: [240-1] LOG:  query:
postgres[23448]: [240-2] UPDATE
postgres[23448]: [240-3]     testtable
postgres[23448]: [240-4] SET
postgres[23448]: [240-5]     price = NULL
postgres[23448]: [240-6] WHERE
postgres[23448]: [240-7]     ident = 10
postgres[23448]: [241] ERROR:  ExecUpdate: Fail to add null value in not null attribute price
postgres[23448]: [242] DEBUG:  AbortCurrentTransaction
postgres[23448]: [243] DEBUG:  StartTransactionCommand
postgres[23448]: [244] LOG:  query: ROLLBACK WORK
====

PostgreSQL version 7.3.4
PyPgSQL version 2.4
OS is Debian Woody

--

-- 
Ivar

-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
Billy G. Allie | 17 Dec 2003 05:58
Picon

Re: PgNumeric and NULL values


Ivar Zarans wrote:
| On Sun, Dec 14, 2003 at 08:53:33PM -0500, Billy G. Allie wrote:
|
|
|>| Updating numeric field with values of '0.00' generates query, trying
|>| update with 'NULL'. Since column is defined as 'NOT NULL', update fails
|>
|>Can you post sample code that exhibits this behavior please.
|
|
| Creaed table as:
| create table testtable (
|     ident int not null,
|     price numeric not null
| );
|
| Inserted test values:
| insert into testtable (ident, price) values (10, 0.00);
|
| Running follofing short test:
| ====
| #!/usr/bin/env python
|
| from pyPgSQL import PgSQL
|
| connstr = '::DBname:DBuser:DBpass:'
| DBConn = PgSQL.connect(connstr)
| Cursor = DBConn.cursor()
|
| price = PgSQL.PgNumeric('0.00')
| ident = 10
|
| qry = """
| UPDATE
|     testtable
| SET
|     price = %s
| WHERE
|     ident = %s
| """
|
| Cursor.execute(qry, price, ident)
| ====
|
| throws exception:
|
| ====
| Traceback (most recent call last):
|   File "./numtest.py", line 21, in ?
|       Cursor.execute(qry, price, ident)
|   File "/usr/lib/python2.3/site-packages/pyPgSQL/PgSQL.py", line 3072,
|                 in execute
|       raise OperationalError, msg
|       libpq.OperationalError: ERROR:  ExecUpdate:
|                 Fail to add null value in not null attribute price
| ====
|
| PostgreSQL log has following query:
|
| ====
| postgres[23448]: [240-1] LOG:  query:
| postgres[23448]: [240-2] UPDATE
| postgres[23448]: [240-3]     testtable
| postgres[23448]: [240-4] SET
| postgres[23448]: [240-5]     price = NULL
| postgres[23448]: [240-6] WHERE
| postgres[23448]: [240-7]     ident = 10
| postgres[23448]: [241] ERROR:  ExecUpdate: Fail to add null value in
not null attribute price
| postgres[23448]: [242] DEBUG:  AbortCurrentTransaction
| postgres[23448]: [243] DEBUG:  StartTransactionCommand
| postgres[23448]: [244] LOG:  query: ROLLBACK WORK
| ====
|
| PostgreSQL version 7.3.4
| PyPgSQL version 2.4
| OS is Debian Woody
|

The following patch will correct the problem.  I also updated CVS on
sourceforge.

*** pyPgSQL/PgSQL.py    22 Nov 2003 05:35:47 -0000      1.38
--- pyPgSQL/PgSQL.py    17 Dec 2003 04:49:08 -0000
***************
*** 1674,1680 ****
~            return PgNumeric(-self.__v, self.__p, self.__s)

~      def _quote(self, forArray=0):
!       if self.__v:
~            if forArray:
~                return '"%s"' % self.__fmtNumeric()
~            else:
--- 1674,1680 ----
~            return PgNumeric(-self.__v, self.__p, self.__s)

~      def _quote(self, forArray=0):
!       if self.__v != None:
~            if forArray:
~                return '"%s"' % self.__fmtNumeric()
~            else:

--
____       | Billy G. Allie    | Domain....: Bill.Allie@...
|  /|      | 7436 Hartwell     | MSN.......: B_G_Allie@...
|-/-|----- | Dearborn, MI 48126|
|/  |LLIE  | (313) 582-1540    |

Gmane