Hello,
partitioned tables in PostgreSQL don't report the correct number of
updated rows, so updates from a mapper fail. Reported by Antonio on
the postgresql-it mailing list.
I was able to reproduce the bug this way:
-- Database
CREATE TABLE xtable (
id serial primary key,
nave_id integer,
data_manovra DATE);
CREATE TABLE xtable2007 (
id integer primary key,
CHECK ( data_manovra BETWEEN '1/1/2007' AND '31/12/2007' )
) INHERITS (xtable);
CREATE RULE xtable2007_upd AS ON UPDATE TO xtable
WHERE NEW.data_manovra BETWEEN '1/1/2007' AND '31/12/2007'
DO INSTEAD UPDATE xtable2007
SET data_manovra = NEW.data_manovra,
nave_id = NEW.nave_id
WHERE id = NEW.id;
INSERT INTO xtable2007 (nave_id, data_manovra) VALUES (10,
'2007-1-2');
# Python
>>> from sqlalchemy import *
>>> e = create_engine("postgres://localhost/tsbug")
>>> meta = BoundMetaData(e)
>>> t = Table('xtable', meta, autoload=True);
>>> class Nave(object): pass
>>> mapper(Nave, t)
>>> ses = create_session(bind_to=e)
>>> nave = ses.query(Nave).get(1)
>>> nave.nave_id = 15
>>> ses.flush()
An obvious fix is reported below, i don't know if there is a better
way to fix it. Furthermore i didn't check for inserts and deletes (if
you wish i could: i just set up the reported db schema: i can ask the
OP a complete example of partitioned table).
Cheers,
-- Daniele
--- sqlalchemy/databases/postgres.py.bak 2007-06-14 12:02:40 +0200
+++ sqlalchemy/databases/postgres.py 2007-06-14 12:02:30 +0200
@@ -283,6 +283,10 @@
else:
return sqltypes.adapt_type(typeobj, pg1_colspecs)
+ def supports_sane_rowcount(self):
+ # It fails for updates on partitioned tables.
+ return False
+
def compiler(self, statement, bindparams, **kwargs):
return PGCompiler(self, statement, bindparams, **kwargs)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---