On 8/12/15 1:04 PM, MR M wrote:
Hi,

Somewhat new to sqlalchemy, and I've read thru a lot of documentation about horizontal sharding and polymorphism features, but I'm still unsure of how to support postgresql partitioned tables with ORM.

on the database side, I have (just a dummy example):

-- start
create table account (
user_id serial not null,
name varchar(100),
primary key(user_id))
;
create table acount_a (
check(substring(name, 1, 1) = 'A')
) inherits (account)
;
create table acount_b (
check(substring(name, 1, 1) = 'B')
) inherits (account)
;
--- end


on the ORM side i just have:

class Account(Base):
    __tablename__ = 'account'
    id = Column('user_id', ....)
    name = Column(Varchar(100)...)


I'd like to insert a new Account(name='Bob'), and have the record be inserted to account_b in code instead of relying on database triggers or rules.

If you're already relying on PG's special features, you would be best off using the triggers as their documentation states. While there might be ways to implement half of PG's documented system on the Python side using various events and other features, it would be complicated and buggy. PG's triggers and stored procedures can certainly handle the entire job of keeping this sharding transparent so I don't see why these have to be reinvented in Python.




--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to