Hi All,I have a few partitioned tables in my PostgreSQL database but I do not know yet how to make the ORM relationship() with partition constraint-exclusion on the instance level. Constraint-exclusion does not work with joins and requires scalar values - the problem is that I would need to add an additional WHERE clause to the primaryjoin (which adds the partition key) if the relationship is accessed from the instance level, e.g. user.addresses. Is there a mechanism in relationship() to distinguish between class-based joins (User.addresses) and instance-level access?
--
You received this message because you are subscribed to a topic in the Google Groups "sqlalchemy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/ov-mYWA7XAM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy+...@googlegroups.com.
To post to this group, send email to sqlal...@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.
Actually that was a bit too early but I tracked the problem down to the many-to-many relationship. Parameters are only interpolated (e.g. %(param_1)s) for the primaryjoin to the secondary table. Is there a technique to force relationship() to interpolate a parameter between the 1st and 3rd table instead of using only table.column=table.column?
On Thu, Dec 5, 2013 at 10:58 AM, Adrian Schreyer <adrian....@gmail.com> wrote:
Never mind,the problem was that I specified the clause in a secondaryjoin and not in the primaryjoin of the relationship().On Thu, Dec 5, 2013 at 10:44 AM, Adrian <adrian....@gmail.com> wrote:Hi All,I have a few partitioned tables in my PostgreSQL database but I do not know yet how to make the ORM relationship() with partition constraint-exclusion on the instance level. Constraint-exclusion does not work with joins and requires scalar values - the problem is that I would need to add an additional WHERE clause to the primaryjoin (which adds the partition key) if the relationship is accessed from the instance level, e.g. user.addresses. Is there a mechanism in relationship() to distinguish between class-based joins (User.addresses) and instance-level access?--
You received this message because you are subscribed to a topic in the Google Groups "sqlalchemy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/ov-mYWA7XAM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy+...@googlegroups.com.
To post to this group, send email to sqlal...@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.
--
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+...@googlegroups.com.
Given the three mappings First, Second and Partitioned, I want to declare a relationship between First and Partitioned. The problem is that Partitioned is partitioned by partition_key which is a column in First but not in Second. Second however contains the identifier that actually links First to specific rows in the partitioned table.
So far the mapping looks like this mock example:
partitioned = relationship("Partitioned",
secondary=Base.metadata.tables['schema.seconds'],
primaryjoin="and_(First.first_id==Second.first_id, First.partition_key==Partitioned.partition_key)",
secondaryjoin="Second.other_id==Partitioned.other_id",
foreign_keys="[Second.first_id, Partitioned.partition_key, Partitioned.other_id]",
uselist=True, innerjoin=True, lazy='dynamic')
It works, but it only interpolates the First.first_id with the actual value which normally makes sense but to make the PostgreSQL constraint-exclusion work the First.partition_key would need to be interpolated with the proper value as well. Right now it is only given as First.partition_key==Partitioned.partition_key.
Does that make sense? I am not sure if my relationship configuration is wrong or if this kind of mapping is simply not supported.
The partitioned relationship actually referred to the tertiary table in both the primary and secondary join - the problem for me was that in the primaryjoin
primaryjoin="and_(First.first_id==Second.first_id, First.partition_key==Partitioned.partition_key)"
only First.first_id will be interpolated with the actual value first_id of the instance in question whereas First.partition_key on the other hand will be interpolated as column object. The problem is that in this case First.partition_key has to be interpolated with the actual value to get the constraint-exclusion to work. In a normal many-to-many relationship this would not be necessary and maybe that is why it only interpolates the values for the join on the secondary table.
The partitioned relationship emits a query like this if the attribute is accessed:
SELECT partitioned.*
FROM partitioned, second, first
WHERE %(param_1)s = second.first_id
AND first.partition_key = partitioned.partition_key
AND second.other_id = partitioned.other_idBut I would need first.partitioned_key to be %(param_2)s.
So far I used a @property around a query function to add the partition_key to query.filter() manually.