On Friday, June 29, 2012 10:20:08 AM UTC-4, Michael Bayer wrote: > > > On Jun 29, 2012, at 8:21 AM, Barry Steyn wrote: > > Hi All > > Firstly, I know that SA does not support Postgres Inheritance "out of the > box". But the concepts for concrete inheritance should allow some support, > at least for what I am trying to do. I am new to SA and Python (about a > month of experience here) and so I don't know if I am barking up the wrong > tree. Here is what I think... > > Each table has a unique "tableoid" column in Postgres. So lets assume this > table structure: > > CREATE TABLE A ( >> id SERIAL Primary Key, >> name text >> ) >> >> CREATE TABLE B ( >> id SERIAL Primary Key, >> name text, >> language text >> ) INHERITS(A) >> > > Table B uses the postgres Inherits. Now lets assume that Postgres has > given table A an oid of 1, and table B an oid of 2. If I do... > > SELECT A.tableoid, * FROM A > > Then the rows that are from table B will have an oid of 2, while those > from A will have an oid of 1. So this mimics a polymorphism in a way *and > I can use this OID as a discriminator.* > > Here is my question (finally): How can I accomplish this in SA using > concrete inheritance and polymorphism. What I want is that when querying > table A, a polymorphic call will load up the class representing B in the > appropriate cases. Here follows EXACTLY what I am trying to do (and the > code will follow after): > > - There are three postgres tables in play: (1) A Users table, (2) An > Authentications table (3) A Password_Authentications table > - Users has a foreignkey into Authorisations > - Password_Authentications is inherited from Authentications > > > what we have for PG inheritance is here: > > http://www.sqlalchemy.org/trac/wiki/UsageRecipes/PostgreSQLInheritance > > as you'll see there, we're not using concrete inheritance, we're using > "single table" inheritance. This because PG's INHERIT feature is designed > to produce a single table interface that reads/writes distinct inheriting > tables transparently. The recipe there is derived from PG's > documentation on how the feature is intended to be used. > > Hi Michael
I did read that recipe before I posted to this group. Unfortunately, single table inheritance does not provide much advantage if the child table has additional columns to the parent - with single table inheritance, one cannot get to those additional child columns. After reading up on concrete table inheritance, I am under the impression that the only thing one needs to implement this is a extinguisher. I could be totally incorrect here. So the question is: Can I accomplish polymorphic inheritance of postgres tables using the tableoid as a polymorphic_identity? -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/f9kdd0exBRYJ. 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.
